-- selection or graphic structure. These are deduced
-- from your reference 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
-- An Interactive entity which is view (or projector)
-- dependent requires recalculation of views in hidden
ComputeSelection(me:mutable; aSelection :mutable Selection from SelectMgr;
aMode : Integer) is redefined virtual private;
---Level: Public
- ---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.
+ ---Purpose: Generates sensitive entities by copying
+ -- them from myReference selection, creates and sets an entity
+ -- owner for this entities and adds them to aSelection
AcceptShapeDecomposition(me) returns Boolean from Standard is
redefined virtual;
//function : ComputeSelection
//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;
aSel->Clear();
if(!myReference->HasSelection(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);
Handle(SelectMgr_EntityOwner) OWN = new SelectMgr_EntityOwner(this);
- Handle(Select3D_SensitiveEntity) SE3D,SNew;
+ Handle(Select3D_SensitiveEntity) SE3D, SNew;
if(TheRefSel->IsEmpty())
myReference->UpdateSelection(aMode);
- for(TheRefSel->Init();TheRefSel->More();TheRefSel->Next()){
- SE3D = *((Handle(Select3D_SensitiveEntity)*) &(TheRefSel->Sensitive()));
- if(!SE3D.IsNull()){
+ for(TheRefSel->Init();TheRefSel->More();TheRefSel->Next())
+ {
+ SE3D = Handle(Select3D_SensitiveEntity)::DownCast(TheRefSel->Sensitive());
+ if(!SE3D.IsNull())
+ {
+ // Get the copy of SE3D
SNew = SE3D->GetConnected(myLocation);
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);
}
}
-// KronSel.Stop();
-// cout<<"fin calcul connexion primitives pour le mode "<<aMode<<endl;
-// KronSel.Show();
}
void AIS_ConnectedInteractive::UpdateLocation()
aPresentation : mutable Presentation from Prs3d)
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;
- aPresentationManager: PresentationManager2d from PrsMgr;
- aPresentation: mutable GraphicObject from Graphic2d;
- aMode: Integer from Standard = 0)
+ aPresentationManager: PresentationManager2d from PrsMgr;
+ aPresentation: mutable GraphicObject from Graphic2d;
+ aMode: Integer from Standard = 0)
+ raises NotImplemented from Standard
+ is redefined;
---Level: Internal
---Purpose: this method should fill the presentation according to the
-- enumerated mode of the application and to the display parameter
-- of the application.
-
- raises NotImplemented from Standard
- is redefined;
+
+ ComputeSelection(me:mutable; aSelection :mutable Selection from SelectMgr;
+ 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;
---C++: return const&
#include <SelectBasics_EntityOwner.hxx>
#include <AIS_MultipleConnectedShape.hxx>
#include <Precision.hxx>
+#include <NCollection_DataMap.hxx>
+#include <NCollection_List.hxx>
//=======================================================================
//function : AIS_ConnectedShape
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
//purpose : Attention fragile...
//=======================================================================
+static Standard_Boolean IsEqual( const TopoDS_Shape& theLeft,
+ const TopoDS_Shape& theRight )
+{
+ return theLeft.IsEqual(theRight);
+}
-void AIS_ConnectedShape::ComputeSelection (const Handle(SelectMgr_Selection)& aSelection,
- const Standard_Integer aMode)
+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();
aSelection->Clear();
// It is checked if there is nothing to do with the reference
if(!myReference->HasSelection(aMode))
myReference->UpdateSelection(aMode);
- const Handle(SelectMgr_Selection)& RefSel = myReference->Selection(aMode);
- if(RefSel->IsEmpty())
- myReference->UpdateSelection(aMode);
- if(RefSel->UpdateStatus()==SelectMgr_TOU_Full)
+ const Handle(SelectMgr_Selection)& aRefSel = myReference->Selection(aMode);
+ if(aRefSel->IsEmpty())
myReference->UpdateSelection(aMode);
- // depending on the type of decomposition, connected primitives are subtracted
- // it is necessary to follow the order of creation of StdSelect_BRepSelectionTool...
+ if(aRefSel->UpdateStatus()==SelectMgr_TOU_Full)
+ myReference->UpdateSelection(aMode);
- TopAbs_ShapeEnum TheType = AIS_Shape::SelectionType(aMode);
- Handle(StdSelect_BRepOwner) OWNR;
- Handle(Select3D_SensitiveEntity) SE,NiouSE;
- TopLoc_Location BidLoc;
-
- switch(TheType){
- case TopAbs_VERTEX:
- case TopAbs_EDGE:
- case TopAbs_WIRE:
- case TopAbs_FACE:
- case TopAbs_SHELL:
+ Handle(StdSelect_BRepOwner) anOwner;
+ TopLoc_Location aBidLoc;
+ Handle(Select3D_SensitiveEntity) aSE, aNewSE;
+ Shapes2EntitiesMap aShapes2EntitiesMap;
+ SensitiveList aSEList;
+ TopoDS_Shape aSubShape;
+
+ // Fill in the map of subshapes and corresponding
+ // sensitive entities associated with aMode
+ for(aRefSel->Init(); aRefSel->More(); aRefSel->Next())
+ {
+ aSE = Handle(Select3D_SensitiveEntity)::DownCast(aRefSel->Sensitive());
+ if(!aSE.IsNull())
{
- TopTools_IndexedMapOfShape subshaps;
- TopExp::MapShapes(myOwnSh,TheType,subshaps);
-
- RefSel->Init();
- for(Standard_Integer I=1;
- I<=subshaps.Extent()&& RefSel->More();
- RefSel->Next(),I++){
-
- SE = *((Handle(Select3D_SensitiveEntity)*) &(RefSel->Sensitive()));
- 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);
- }
+ anOwner = Handle(StdSelect_BRepOwner)::DownCast(aSE->OwnerId());
+ if(!anOwner.IsNull())
+ {
+ aSubShape = anOwner->Shape();
+ if(!aShapes2EntitiesMap.IsBound(aSubShape))
+ {
+ aShapes2EntitiesMap.Bind(aSubShape, aSEList);
+ }
+ aShapes2EntitiesMap(aSubShape).Append(aSE);
}
- break;
}
+ }
+
+ // 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);
- case TopAbs_SHAPE:
- default:
+ SensitiveList::Iterator aListIt(aSEList);
+ for(; aListIt.More(); aListIt.Next())
{
- // 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);
+ 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);
}
- break;
+ 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);
-
+
+ StdSelect::SetDrawerForBRepOwner(aSelection,myDrawer);
}
-
//=======================================================================
//function : Shape
/*ABD 29/10/04 Transform Persistence of Presentation( pan, zoom, rotate ) */
default: {
key.id = openglWsId;
- TsmSendMessage (telem, DisplayTraverse, node->elem.data, 0, &key);
+ TsmSendMessage (telem, DisplayTraverse, node->elem.data, 1, &key);
}
}
}
//==================================================
Select3D_SensitiveBox::Select3D_SensitiveBox(const Handle(SelectBasics_EntityOwner)& OwnerId,
- const Bnd_Box& BBox):
+ const Bnd_Box& BBox):
Select3D_SensitiveEntity(OwnerId),
mybox3d(BBox){}
-
//==================================================
// Function: Constructor
// Purpose :
Select3D_SensitiveBox::
Select3D_SensitiveBox(const Handle(SelectBasics_EntityOwner)& OwnerId,
- const Standard_Real XMin,
- const Standard_Real YMin,
- const Standard_Real ZMin,
- const Standard_Real XMax,
- const Standard_Real YMax,
- const Standard_Real ZMax):
+ const Standard_Real XMin,
+ const Standard_Real YMin,
+ const Standard_Real ZMin,
+ const Standard_Real XMax,
+ const Standard_Real YMax,
+ const Standard_Real ZMax):
Select3D_SensitiveEntity(OwnerId)
{
mybox3d.Update(XMin,YMin,ZMin,XMax,YMax,ZMax);
}
-
//==================================================
// Function: Project
// Purpose :
//==================================================
+
void Select3D_SensitiveBox::
Project(const Handle(Select3D_Projector)& aProj)
{
Select3D_SensitiveEntity::Project(aProj); // to set the field last proj...
- if(HasLocation()){
+ if(HasLocation())
+ {
Bnd_Box B = mybox3d.Transformed(Location().Transformation());
ProjectBox(aProj,B);
}
}
//==================================================
-// Function:
+// Function: Areas
// Purpose :
//==================================================
+
void Select3D_SensitiveBox::
Areas(SelectBasics_ListOfBox2d& aSeq)
{ aSeq.Append(mybox2d);}
-
//=======================================================================
//function : GetConnected
//purpose :
return NiouEnt;
}
-
-
//==================================================
-// Function:
+// Function: Matches
// Purpose :
//==================================================
Standard_Boolean Select3D_SensitiveBox::
-Matches(const Standard_Real X,
- const Standard_Real Y,
- const Standard_Real aTol,
- Standard_Real& DMin)
+Matches(const Standard_Real X,
+ const Standard_Real Y,
+ const Standard_Real aTol,
+ Standard_Real& DMin)
{
Select3D_SensitiveEntity::Matches(X,Y,aTol,DMin);
DMin=0.;
return Standard_True;
-
}
//==================================================
-// Function:
+// Function: Matches
// Purpose :
//==================================================
Standard_Boolean Select3D_SensitiveBox::
Matches (const Standard_Real XMin,
- const Standard_Real YMin,
- const Standard_Real XMax,
- const Standard_Real YMax,
- const Standard_Real aTol)
+ const Standard_Real YMin,
+ const Standard_Real XMax,
+ const Standard_Real YMax,
+ const Standard_Real aTol)
{
Bnd_Box2d BoundBox;
BoundBox.Update(XMin-aTol,YMin-aTol,XMax+aTol,YMax+aTol);
return(!BoundBox.IsOut(mybox2d));
}
-
//=======================================================================
//function : Matches
//purpose :
Standard_Boolean Select3D_SensitiveBox::
Matches (const TColgp_Array1OfPnt2d& aPoly,
- const Bnd_Box2d& aBox,
- const Standard_Real aTol)
-{
+ const Bnd_Box2d& aBox,
+ const Standard_Real aTol)
+{
return(!aBox.IsOut(mybox2d));
}
-
//=======================================================================
//function : Dump
//purpose :
S<<"\t\t PMin [ "<<XMin<<" , "<<YMin<<" , "<<ZMin<<" ]";
S<<"\t\t PMax [ "<<XMax<<" , "<<YMax<<" , "<<ZMax<<" ]"<<endl;
- if(FullDump){
+ if(FullDump)
+ {
// S<<"\t\t\tOwner:"<<myOwnerId<<endl;
- Select3D_SensitiveEntity::DumpBox(S,mybox2d);}
-
+ Select3D_SensitiveEntity::DumpBox(S,mybox2d);
+ }
}
//=======================================================================
void Select3D_SensitiveBox::ProjectBox(const Handle(Select3D_Projector)& aPrj,
- const Bnd_Box& aBox)
+ const Bnd_Box& aBox)
{
mybox2d.SetVoid();
gp_Pnt2d curp2d;
Location from TopLoc,
Pnt from Select3D,
Pnt2d from Select3D,
- Projector from Select3D
+ Projector from Select3D,
+ SensitiveEntity from Select3D,
+ Circle from Geom
is
Create (OwnerId : EntityOwner from SelectBasics;
FilledCircle : Boolean from Standard = Standard_False)
returns mutable SensitiveCircle;
---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
-- must be equal to the last point of apolyg3d.
GetPoint3d(me;rank:Integer) returns Pnt from gp;
---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;
myDetectedIndex : Integer from Standard; -- used for depth...
myCenter2D : Pnt2d 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;
#include <Select3D_Pnt2d.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,
const Standard_Integer anInputNumber)
{
return 2*anInputNumber+1;
return 1;
}
+
static Standard_Integer S3D_GetArcNBPoints(const Handle(Geom_Circle)& C,
const Standard_Integer anInputNumber)
{
return 2*anInputNumber-1;
return 1;
}
-
+
+//=======================================================================
+//function : Select3D_SensitiveCircle (constructor)
+//purpose : Definition of a sensitive circle
+//=======================================================================
+
Select3D_SensitiveCircle::
Select3D_SensitiveCircle(const Handle(SelectBasics_EntityOwner)& OwnerId,
- const Handle(Geom_Circle)& TheCircle,
- const Standard_Boolean FilledCircle,
- const Standard_Integer NbPoints):
+ const Handle(Geom_Circle)& TheCircle,
+ const Standard_Boolean FilledCircle,
+ const Standard_Integer NbPoints):
Select3D_SensitivePoly(OwnerId, S3D_GetCircleNBPoints(TheCircle,NbPoints)),
myFillStatus(FilledCircle),
-myDetectedIndex(-1)
+myDetectedIndex(-1),
+myCircle(TheCircle),
+mystart(0),
+myend(0)
{
- if(mynbpoints!=1){
- gp_Pnt p1,p2;//,pmid;
- gp_Vec v1;//,v2;
+ if(mynbpoints!=1)
+ {
+ gp_Pnt p1,p2;
+ gp_Vec v1;
Standard_Real ustart = TheCircle->FirstParameter(),uend = TheCircle->LastParameter();
Standard_Real du = (uend-ustart)/NbPoints;
Standard_Real R = TheCircle->Radius();
// Get myCenter3D
myCenter3D = ((Select3D_Pnt*)mypolyg3d)[0];
}
-
}
//=======================================================================
-//function : Select3D_SensitiveCircle (constructeur)
+//function : Select3D_SensitiveCircle (constructor)
//purpose : Definition of a sensitive arc
//=======================================================================
+
Select3D_SensitiveCircle::
Select3D_SensitiveCircle(const Handle(SelectBasics_EntityOwner)& OwnerId,
- const Handle(Geom_Circle)& TheCircle,
- const Standard_Real u1,
- const Standard_Real u2,
- const Standard_Boolean FilledCircle,
- const Standard_Integer NbPoints):
+ const Handle(Geom_Circle)& TheCircle,
+ const Standard_Real u1,
+ const Standard_Real u2,
+ const Standard_Boolean FilledCircle,
+ const Standard_Integer NbPoints):
Select3D_SensitivePoly(OwnerId, S3D_GetArcNBPoints(TheCircle,NbPoints)),
myFillStatus(FilledCircle),
-myDetectedIndex(-1)
+myDetectedIndex(-1),
+myCircle(TheCircle),
+mystart(u1),
+myend(u2)
{
-
- if(mynbpoints > 1){
- gp_Pnt p1,p2;//,pmid;
- gp_Vec v1;//,v2;
-
- Standard_Real ustart = u1;
- Standard_Real uend = u2;
+ if(mynbpoints > 1)
+ {
+ gp_Pnt p1,p2;
+ gp_Vec v1;
- if (u1 > u2) {ustart=u1;uend=u2;}
+ if (u1 > u2)
+ {
+ mystart = u2;
+ myend = u1;
+ }
- Standard_Real du = (uend-ustart)/(NbPoints-1);
+ Standard_Real du = (myend-mystart)/(NbPoints-1);
Standard_Real R = TheCircle->Radius();
Standard_Integer rank = 1;
- Standard_Real curu =ustart;
-
-
+ Standard_Real curu = mystart;
for(Standard_Integer i=1;i<=NbPoints-1;i++)
{
rank++;
curu+=du;
}
- TheCircle->D0(uend,p1);
+ TheCircle->D0(myend,p1);
((Select3D_Pnt*)mypolyg3d)[NbPoints*2-2] = p1;
// Get myCenter3D
myCenter3D = TheCircle->Location();
//function : Select3D_SensitiveCircle
//purpose :
//=======================================================================
+
Select3D_SensitiveCircle::Select3D_SensitiveCircle(const Handle(SelectBasics_EntityOwner)& OwnerId,
- const Handle(TColgp_HArray1OfPnt)& Thepolyg3d,
- const Standard_Boolean FilledCircle):
+ const Handle(TColgp_HArray1OfPnt)& Thepolyg3d,
+ const Standard_Boolean FilledCircle):
Select3D_SensitivePoly(OwnerId, Thepolyg3d),
myFillStatus(FilledCircle),
-myDetectedIndex(-1)
+myDetectedIndex(-1),
+mystart(0),
+myend(0)
{
if (mynbpoints > 1)
ComputeCenter3D();
myCenter3D = ((Select3D_Pnt*)mypolyg3d)[0];
}
+//=======================================================================
+//function : Select3D_SensitiveCircle
+//purpose :
+//=======================================================================
+
Select3D_SensitiveCircle::Select3D_SensitiveCircle(const Handle(SelectBasics_EntityOwner)& OwnerId,
- const TColgp_Array1OfPnt& Thepolyg3d,
- const Standard_Boolean FilledCircle):
+ const TColgp_Array1OfPnt& Thepolyg3d,
+ const Standard_Boolean FilledCircle):
Select3D_SensitivePoly(OwnerId, Thepolyg3d),
myFillStatus(FilledCircle),
-myDetectedIndex(-1)
+myDetectedIndex(-1),
+mystart(0),
+myend(0)
{
if (mynbpoints > 1)
ComputeCenter3D();
myCenter3D = ((Select3D_Pnt*)mypolyg3d)[0];
}
+//=======================================================================
+//function : Matches
+//purpose :
+//=======================================================================
+
Standard_Boolean Select3D_SensitiveCircle::
Matches(const Standard_Real X,
- const Standard_Real Y,
- const Standard_Real aTol,
- Standard_Real& DMin)
+ const Standard_Real Y,
+ const Standard_Real aTol,
+ Standard_Real& DMin)
{
-
if(mynbpoints>1)
{
Standard_Boolean Found = Standard_False;
return Found;
}
return Standard_True;
-
}
+//=======================================================================
+//function : Matches
+//purpose :
+//=======================================================================
+
Standard_Boolean Select3D_SensitiveCircle::
Matches(const Standard_Real XMin,
- const Standard_Real YMin,
- const Standard_Real XMax,
- const Standard_Real YMax,
- const Standard_Real aTol)
+ const Standard_Real YMin,
+ const Standard_Real XMax,
+ const Standard_Real YMax,
+ const Standard_Real aTol)
{
myDetectedIndex =-1;
Bnd_Box2d abox;
return Standard_True;
}
-
//=======================================================================
//function : Matches
//purpose :
Standard_Boolean Select3D_SensitiveCircle::
Matches (const TColgp_Array1OfPnt2d& aPoly,
- const Bnd_Box2d& aBox,
- const Standard_Real aTol)
+ const Bnd_Box2d& aBox,
+ const Standard_Real aTol)
{
Standard_Real Umin,Vmin,Umax,Vmax;
aBox.Get(Umin,Vmin,Umax,Vmax);
Tolv = 1e-7;
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]);
if(RES!=1) return Standard_False;
}
return Standard_True;
}
-
-
+//=======================================================================
+//function : ArrayBounds
+//purpose :
+//=======================================================================
void Select3D_SensitiveCircle::
ArrayBounds(Standard_Integer & Low,
- Standard_Integer & Up) const
+ Standard_Integer & Up) const
{
Low = 0;
Up = mynbpoints-1;
}
+//=======================================================================
+//function : GetPoint3d
+//purpose :
+//=======================================================================
gp_Pnt Select3D_SensitiveCircle::
GetPoint3d(const Standard_Integer Rank) const
S<<"\t\tExisting Location"<<endl;
- if(FullDump){
+ if(FullDump)
+ {
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];
nbpt++;
}
}
}
+
+//=======================================================================
+//function : ComputeDepth
+//purpose :
+//=======================================================================
+
Standard_Real Select3D_SensitiveCircle::ComputeDepth(const gp_Lin& EyeLine) const
{
gp_Pnt CDG;
- if(myDetectedIndex==-1){
+ if(myDetectedIndex==-1)
+ {
gp_XYZ CurCoord(((Select3D_Pnt*)mypolyg3d)[0]);
Standard_Boolean isclosed = 1==mynbpoints;
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];
nbpt++;
}
CDG.SetXYZ(CurCoord);
}
- else{
+ else
+ {
gp_XYZ CurCoord(((Select3D_Pnt*)mypolyg3d)[myDetectedIndex]);
CurCoord+=((Select3D_Pnt*)mypolyg3d)[myDetectedIndex+1];
CurCoord+=((Select3D_Pnt*)mypolyg3d)[myDetectedIndex+2];
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)
{
Select3D_SensitivePoly::Project(aProjector);
myCenter2D = aCenter;
}
+//=======================================================================
+//function : ComputeCenter3D
+//purpose :
+//=======================================================================
+
void Select3D_SensitiveCircle::ComputeCenter3D()
{
gp_XYZ aCenter(0., 0., 0.);
- if (mynbpoints > 1)
+ if(mynbpoints > 1)
{
// The mass of points system
Standard_Integer aMass = mynbpoints - 1;
// 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];
}
myCenter3D = aCenter / aMass;
}
- else if (mynbpoints == 1)
+ else if (mynbpoints == 1)
{
myCenter3D = ((Select3D_Pnt*)mypolyg3d)[0];
}
// It can lead to incorrect computation of
// parameter DMin in method Matches.
// In spite of this myCenter3D isn't left uninitialized
- else
- {
+ else
+ {
myCenter3D = aCenter;
}
}
Array1OfPnt2d from TColgp,
HArray1OfPnt from TColgp,
Box2d from Bnd,
- Location from TopLoc
+ Location from TopLoc,
+ SensitiveEntity from Select3D
is
---Level: Public
---Purpose: Creation of Sensitive Curve from Points.
-- Warning : This Method should disappear in the next version...
-
+
Matches(me :mutable;
X,Y : Real from Standard;
aTol: Real from Standard;
---Category: Internal Methods
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
mylastseg : Integer from Standard;
+ myCurve : Curve from Geom;
end SensitiveCurve;
//==================================================
-// Function:
+// Function: Creation
// Purpose :
//==================================================
Select3D_SensitiveCurve
::Select3D_SensitiveCurve(const Handle(SelectBasics_EntityOwner)& OwnerId,
- const Handle(Geom_Curve)& C,
- const Standard_Integer NbPoints):
+ const Handle(Geom_Curve)& C,
+ const Standard_Integer NbPoints):
Select3D_SensitivePoly(OwnerId, NbPoints),
-mylastseg(0)
+mylastseg(0),
+myCurve(C)
{
LoadPoints(C,NbPoints);
}
+
//==================================================
// Function: Creation
// Purpose :
//==================================================
+
Select3D_SensitiveCurve
::Select3D_SensitiveCurve(const Handle(SelectBasics_EntityOwner)& OwnerId,
- const Handle(TColgp_HArray1OfPnt)& ThePoints):
+ const Handle(TColgp_HArray1OfPnt)& ThePoints):
Select3D_SensitivePoly(OwnerId, ThePoints),
-mylastseg(0)
+mylastseg(0)
{
}
+
//==================================================
// Function: Creation
// Purpose :
//==================================================
+
Select3D_SensitiveCurve
::Select3D_SensitiveCurve(const Handle(SelectBasics_EntityOwner)& OwnerId,
- const TColgp_Array1OfPnt& ThePoints):
+ const TColgp_Array1OfPnt& ThePoints):
Select3D_SensitivePoly(OwnerId, ThePoints),
-mylastseg(0)
+mylastseg(0)
{
}
// Function: Matches
// Purpose :
//==================================================
+
Standard_Boolean Select3D_SensitiveCurve
::Matches(const Standard_Real X,
- const Standard_Real Y,
- const Standard_Real aTol,
- Standard_Real& DMin)
+ const Standard_Real Y,
+ const Standard_Real aTol,
+ Standard_Real& DMin)
{
Standard_Integer Rank;
TColgp_Array1OfPnt2d aArrayOf2dPnt(1, mynbpoints);
mylastseg = Rank;
// compute and validate the depth (::Depth()) along the eyeline
return Select3D_SensitiveEntity::Matches (X, Y, aTol, DMin);
-
}
return Standard_False;
-
}
+
//==================================================
// Function: Matches
// Purpose : know if a box touches the projected polygon
Standard_Boolean Select3D_SensitiveCurve::
Matches (const Standard_Real XMin,
- const Standard_Real YMin,
- const Standard_Real XMax,
- const Standard_Real YMax,
- const Standard_Real aTol)
-{
+ const Standard_Real YMin,
+ const Standard_Real XMax,
+ const Standard_Real YMax,
+ const Standard_Real aTol)
+{
Bnd_Box2d BoundBox;
BoundBox.Update(XMin-aTol,YMin-aTol,XMax+aTol,YMax+aTol);
Standard_Boolean Select3D_SensitiveCurve::
Matches (const TColgp_Array1OfPnt2d& aPoly,
- const Bnd_Box2d& aBox,
- const Standard_Real aTol)
-{
+ const Bnd_Box2d& aBox,
+ const Standard_Real aTol)
+{
Standard_Real Umin,Vmin,Umax,Vmax;
aBox.Get(Umin,Vmin,Umax,Vmax);
Standard_Real Tolu,Tolv;
Tolv = 1e-7;
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]);
if(RES!=1) return Standard_False;
}
return Standard_True;
}
-
-
//==================================================
-// Function:
+// Function: LoadPoints
// Purpose :
//==================================================
S<<"\t\tNumber Of Points :"<<mynbpoints<<endl;
- if(FullDump){
+ if(FullDump)
+ {
// S<<"\t\t\tOwner:"<<myOwnerId<<endl;
Select3D_SensitiveEntity::DumpBox(S,mybox2d);
}
}
+
//=======================================================================
//function : ComputeDepth
//purpose :
Standard_Real Select3D_SensitiveCurve::ComputeDepth(const gp_Lin& EyeLine) const
{
-
if(mylastseg==0) return Precision::Infinite(); // non implemente actuellement...
gp_XYZ TheCDG(((Select3D_Pnt*)mypolyg3d)[mylastseg]);
TheCDG+=((Select3D_Pnt*)mypolyg3d)[mylastseg+1];
TheCDG/=2.;
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;
+}
\ No newline at end of file
GetConnected(me:mutable;aLocation: Location from TopLoc)
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
-- sensitive entity which can accept another connected
-- sensitive entity.//can be connected to another sensitive entity.
//=======================================================================
Standard_Boolean Select3D_SensitiveEntity::Matches(const Standard_Real X,
- const Standard_Real Y,
- const Standard_Real aTol,
- Standard_Real& DMin)
+ const Standard_Real Y,
+ const Standard_Real aTol,
+ Standard_Real& DMin)
{
if (!mylastprj.IsNull())
{
//=======================================================================
Standard_Boolean Select3D_SensitiveEntity::Matches(const Standard_Real XMin,
- const Standard_Real YMin,
- const Standard_Real XMax,
- const Standard_Real YMax,
- const Standard_Real aTol)
+ const Standard_Real YMin,
+ const Standard_Real XMax,
+ const Standard_Real YMax,
+ const Standard_Real aTol)
{
return Standard_False;
}
//=======================================================================
Standard_Boolean Select3D_SensitiveEntity::Matches(const TColgp_Array1OfPnt2d& aPoly,
- const Bnd_Box2d& aBox,
- const Standard_Real aTol)
+ const Bnd_Box2d& aBox,
+ const Standard_Real aTol)
{
return Standard_False;
}
void Select3D_SensitiveEntity::DumpBox(Standard_OStream& S,const Bnd_Box2d& b2d)
{
- if(!b2d.IsVoid()){
+ if(!b2d.IsVoid())
+ {
Standard_Real xmin,ymin,xmax,ymax;
b2d.Get(xmin,ymin,xmax,ymax);
S<<"\t\t\tBox2d: PMIN ["<<xmin<<" , "<<ymin<<"]"<<endl;
S<<"\t\t\t PMAX ["<<xmax<<" , "<<ymax<<"]"<<endl;
}
-
}
//=======================================================================
if(aLoc.IsIdentity() || aLoc == Location()) return;
if(!HasLocation())
SetLocation(aLoc);
- else {
+ else
+ {
TopLoc_Location compLoc = aLoc * Location();
- SetLocation(compLoc);}
+ SetLocation(compLoc);
+ }
}
//=======================================================================
//=======================================================================
gp_Lin Select3D_SensitiveEntity::GetEyeLine(const Standard_Real X,
- const Standard_Real Y) const
+ const Standard_Real Y) const
{
gp_Lin L;
if (!mylastprj.IsNull())
}
//=======================================================================
-//function : GetConnected
+//function : SetLastDepth
//purpose :
//=======================================================================
void Select3D_SensitiveEntity::SetLastDepth(const Standard_Real aDepth)
Array1OfPnt2d from TColgp,
Box2d from Bnd,
TypeOfSensitivity from Select3D,
- Location from TopLoc
+ Location from TopLoc,
+ SensitiveEntity from Select3D
is
-- owner OwnerId, the array of points ThePoints, and
-- the sensitivity type Sensitivity.
-- The array of points is the outer polygon of the geometric face.
-
+
Matches(me :mutable;
X,Y : Real from Standard;
aTol: Real from Standard;
-- in some particular case, a custom sensitive face class can be implemented at application level
-- 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
Select3D_SensitiveFace::
Select3D_SensitiveFace(const Handle(SelectBasics_EntityOwner)& OwnerId,
- const TColgp_Array1OfPnt& ThePoints,
- const Select3D_TypeOfSensitivity aType):
+ const TColgp_Array1OfPnt& ThePoints,
+ const Select3D_TypeOfSensitivity aType):
Select3D_SensitivePoly(OwnerId, ThePoints),
mytype (aType),
myDetectedIndex(-1)
}
//==================================================
-// Function:
+// Function: Creation
// Purpose :
//==================================================
Select3D_SensitiveFace::
Select3D_SensitiveFace(const Handle(SelectBasics_EntityOwner)& OwnerId,
- const Handle(TColgp_HArray1OfPnt)& ThePoints,
- const Select3D_TypeOfSensitivity aType):
+ const Handle(TColgp_HArray1OfPnt)& ThePoints,
+ const Select3D_TypeOfSensitivity aType):
Select3D_SensitivePoly(OwnerId, ThePoints),
mytype (aType),
myDetectedIndex(-1)
}
//==================================================
-// Function:
+// Function: Matches
// Purpose :
//==================================================
Standard_Boolean Select3D_SensitiveFace::
Matches(const Standard_Real X,
- const Standard_Real Y,
- const Standard_Real aTol,
- Standard_Real& DMin)
+ const Standard_Real Y,
+ const Standard_Real aTol,
+ Standard_Real& DMin)
{
#ifndef DEB
Standard_Real DMin2 = 0.;
Standard_Real DMin2;
#endif
Standard_Real Xmin,Ymin,Xmax,Ymax;
- if(!Bnd_Box2d(mybox2d).IsVoid()){
+ if(!Bnd_Box2d(mybox2d).IsVoid())
+ {
Bnd_Box2d(mybox2d).Get(Xmin,Ymin,Xmax,Ymax);
DMin2 = gp_XY(Xmax-Xmin,Ymax-Ymin).SquareModulus();
}
gp_XY CDG(0.,0.);
// for(Standard_Integer I=1;I<=Nbp-1;I++){
Standard_Integer I;
- for(I=1;I<mynbpoints-1;I++){
+ for(I=1;I<mynbpoints-1;I++)
+ {
CDG+=((Select3D_Pnt2d*)mypolyg2d)[I-1];
}
- if(mynbpoints>1){
+ if(mynbpoints>1)
+ {
CDG/= (mynbpoints-1);
}
DMin2=Min(DMin2,gp_XY(CDG.X()-X,CDG.Y()-Y).SquareModulus());
DMin = Sqrt(DMin2);
-
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);
V1-=((Select3D_Pnt2d*)mypolyg2d)[I-1];
V-=((Select3D_Pnt2d*)mypolyg2d)[I-1];
{
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...
TColgp_Array1OfPnt2d aArrayOf2dPnt(1, mynbpoints);
Standard_Integer TheStat = TheInOutTool.SiDans(gp_Pnt2d(X,Y));
Standard_Boolean res(Standard_False);
- switch(TheStat){
+ switch(TheStat)
+ {
case 0:
res = Standard_True;
case 1:
{
- if(mytype!=Select3D_TOS_BOUNDARY)
- res = Standard_True;
+ if(mytype!=Select3D_TOS_BOUNDARY)
+ res = Standard_True;
}
}
if (res)
Standard_Boolean Select3D_SensitiveFace::
Matches (const Standard_Real XMin,
- const Standard_Real YMin,
- const Standard_Real XMax,
- const Standard_Real YMax,
- const Standard_Real aTol)
-{
+ const Standard_Real YMin,
+ const Standard_Real XMax,
+ const Standard_Real YMax,
+ const Standard_Real aTol)
+{
Bnd_Box2d BoundBox;
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;
}
return Standard_True;
Standard_Boolean Select3D_SensitiveFace::
Matches (const TColgp_Array1OfPnt2d& aPoly,
- const Bnd_Box2d& aBox,
- const Standard_Real aTol)
-{
+ const Bnd_Box2d& aBox,
+ const Standard_Real aTol)
+{
Standard_Real Umin,Vmin,Umax,Vmax;
aBox.Get(Umin,Vmin,Umax,Vmax);
Standard_Real Tolu,Tolv;
Tolv = 1e-7;
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]);
if(RES!=1) return Standard_False;
}
return Standard_True;
}
-
//=======================================================================
//function : Dump
//purpose :
//=======================================================================
+
void Select3D_SensitiveFace::Dump(Standard_OStream& S,const Standard_Boolean FullDump) const
{
S<<"\tSensitiveFace 3D :"<<endl;;
if(mytype==Select3D_TOS_BOUNDARY)
S<<"\t\tSelection Of Bounding Polyline Only"<<endl;
- if(FullDump){
+ if(FullDump)
+ {
S<<"\t\tNumber Of Points :"<<mynbpoints<<endl;
// S<<"\t\t\tOwner:"<<myOwnerId<<endl;
//function : ComputeDepth
//purpose :
//=======================================================================
+
Standard_Real Select3D_SensitiveFace::ComputeDepth(const gp_Lin& EyeLine) const
{
Standard_Real aDepth = Precision::Infinite();
}
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;
+}
\ No newline at end of file
---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)
returns ListOfSensitive from Select3D;
#include <Select3D_ListIteratorOfListOfSensitive.hxx>
#include <Precision.hxx>
+//=======================================================================
+//function : Creation
+//purpose :
+//=======================================================================
Select3D_SensitiveGroup::Select3D_SensitiveGroup(const Handle(SelectBasics_EntityOwner)& OwnerId,
- const Standard_Boolean MatchAll):
+ const Standard_Boolean MatchAll):
Select3D_SensitiveEntity(OwnerId),
myMustMatchAll(MatchAll),
myLastRank(0),
{
}
-Select3D_SensitiveGroup::Select3D_SensitiveGroup(const Handle(SelectBasics_EntityOwner)& OwnerId,
- Select3D_ListOfSensitive& TheList,
- const Standard_Boolean MatchAll):
+//=======================================================================
+//function : Creation
+//purpose :
+//=======================================================================
+Select3D_SensitiveGroup::Select3D_SensitiveGroup(const Handle(SelectBasics_EntityOwner)& OwnerId,
+ Select3D_ListOfSensitive& TheList,
+ const Standard_Boolean MatchAll):
Select3D_SensitiveEntity(OwnerId),
myMustMatchAll(MatchAll),
myLastRank(0),
//function : Add
//purpose : No control of entities inside
//=======================================================================
+
void Select3D_SensitiveGroup::Add(Select3D_ListOfSensitive& LL)
{myList.Append(LL);}
//function : Add
//purpose :
//=======================================================================
+
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;
}
myList.Append(aSensitive);
//function : Remove
//purpose :
//=======================================================================
+
void Select3D_SensitiveGroup::Remove(const Handle(Select3D_SensitiveEntity)& aSensitive)
{
- for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next()){
- if(It.Value()==aSensitive){
+ for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
+ {
+ if(It.Value()==aSensitive)
+ {
myList.Remove(It);
return;
}
//function : IsIn
//purpose :
//=======================================================================
+
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)
return Standard_True;
}
return Standard_False;
-
}
+
//=======================================================================
//function : Clear
//purpose :
//=======================================================================
+
void Select3D_SensitiveGroup::Clear()
{myList.Clear();}
{
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);
}
}
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);
}
}
{
Handle(Select3D_SensitiveGroup) newgroup = new Select3D_SensitiveGroup(myOwnerId,myMustMatchAll);
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));
}
newgroup->Add(LL);
{
if(aLoc.IsIdentity()) return;
+ for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
+ {
+ It.Value()->SetLocation(aLoc);
+ }
+
if(HasLocation())
if(aLoc == Location()) return;
Select3D_SensitiveEntity::SetLocation(aLoc);
- for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next()){
- if(It.Value()->HasLocation()){
- if(It.Value()->Location()!=aLoc)
- It.Value()->SetLocation(It.Value()->Location()*aLoc);
+ for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
+ {
+ if(It.Value()->HasLocation())
+ {
+ if(It.Value()->Location()!=aLoc)
+ It.Value()->SetLocation(It.Value()->Location()*aLoc);
}
else
It.Value()->SetLocation(aLoc);
-
}
}
//function : ResetLocation
//purpose :
//=======================================================================
+
void Select3D_SensitiveGroup::ResetLocation()
{
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())
It.Value()->SetLocation(It.Value()->Location()*Location().Inverted());
else
It.Value()->ResetLocation();
-
}
Select3D_SensitiveEntity::ResetLocation();
}
//function : Matches
//purpose :
//=======================================================================
-Standard_Boolean Select3D_SensitiveGroup::Matches(const Standard_Real X,
- const Standard_Real Y,
- const Standard_Real aTol,
- Standard_Real& DMin)
+
+Standard_Boolean Select3D_SensitiveGroup::Matches(const Standard_Real X,
+ const Standard_Real Y,
+ const Standard_Real aTol,
+ Standard_Real& DMin)
{
myLastRank = 0;
myLastTol = aTol;
//purpose : si on doit tout matcher, on ne repond oui que si toutes
// les primitives repondent oui
//=======================================================================
-Standard_Boolean Select3D_SensitiveGroup::Matches(const Standard_Real XMin,
- const Standard_Real YMin,
- const Standard_Real XMax,
- const Standard_Real YMax,
- const Standard_Real aTol)
+Standard_Boolean Select3D_SensitiveGroup::Matches(const Standard_Real XMin,
+ const Standard_Real YMin,
+ const Standard_Real XMax,
+ const Standard_Real YMax,
+ const Standard_Real aTol)
{
Standard_Boolean result(Standard_True);
- for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next()){
- if(It.Value()->Matches(XMin,YMin,XMax,YMax,aTol)){
+ for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
+ {
+ if(It.Value()->Matches(XMin,YMin,XMax,YMax,aTol))
+ {
if(!myMustMatchAll)
- return Standard_True;
+ return Standard_True;
}
// ca ne matches pas..
- else {
- if(myMustMatchAll)
- return Standard_False;
- else
- result = Standard_False;
+ else
+ {
+ if(myMustMatchAll)
+ return Standard_False;
+ else
+ result = Standard_False;
}
}
return result;
Standard_Boolean Select3D_SensitiveGroup::
Matches (const TColgp_Array1OfPnt2d& aPoly,
- const Bnd_Box2d& aBox,
- const Standard_Real aTol)
+ const Bnd_Box2d& aBox,
+ const Standard_Real aTol)
{
Standard_Boolean result(Standard_True);
- for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next()){
- if(It.Value()->Matches(aPoly, aBox, aTol)){
- if(!myMustMatchAll)
- return Standard_True;
+ for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
+ {
+ if(It.Value()->Matches(aPoly, aBox, aTol))
+ {
+ if(!myMustMatchAll)
+ return Standard_True;
}
- else {
- if(myMustMatchAll)
- return Standard_False;
- else
- result = Standard_False;
+ else
+ {
+ if(myMustMatchAll)
+ return Standard_False;
+ else
+ result = Standard_False;
}
}
return result;
}
-
//=======================================================================
//function : ComputeDepth
//purpose : to optimise, the minimum depth for
//function : MaxBoxes
//purpose :
//=======================================================================
+
Standard_Integer Select3D_SensitiveGroup::MaxBoxes() const
{
Standard_Integer nbboxes(0);
return nbboxes;
}
+//=======================================================================
+//function : SetLastPrj
+//purpose :
+//=======================================================================
+
void Select3D_SensitiveGroup::SetLastPrj(const Handle(Select3D_Projector)& Prj)
{
Select3D_SensitiveEntity::SetLastPrj(Prj);
for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
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);
+}
#include <CSLib_Class2d.hxx>
//==================================================
-// Function:
+// Function: Creation
// Purpose :
//==================================================
Select3D_SensitivePoint
::Select3D_SensitivePoint(const Handle(SelectBasics_EntityOwner)& anOwner,
- const gp_Pnt& aPoint):
+ const gp_Pnt& aPoint):
Select3D_SensitiveEntity(anOwner)
{
SetSensitivityFactor(4.);
}
//==================================================
-// Function:
+// Function: Project
// Purpose :
//==================================================
+
void Select3D_SensitivePoint
::Project (const Handle(Select3D_Projector)& aProj)
{
gp_Pnt2d aPoint2d;
if(!HasLocation())
aProj->Project(mypoint, aPoint2d);
- else{
+ else
+ {
gp_Pnt aP(mypoint.x, mypoint.y, mypoint.z);
aProj->Project(aP.Transformed(Location().Transformation()), aPoint2d);
}
}
//==================================================
-// Function:
+// Function: Areas
// Purpose :
//==================================================
+
void Select3D_SensitivePoint
::Areas(SelectBasics_ListOfBox2d& boxes)
{
boxes.Append(abox);
}
-
//==================================================
-// Function:
+// Function: Matches
// Purpose :
//==================================================
+
Standard_Boolean Select3D_SensitivePoint
::Matches(const Standard_Real X,
- const Standard_Real Y,
- const Standard_Real aTol,
- Standard_Real& DMin)
+ const Standard_Real Y,
+ const Standard_Real aTol,
+ Standard_Real& DMin)
{
DMin = gp_Pnt2d(X,Y).Distance(myprojpt);
if(DMin<=aTol*SensitivityFactor())
return Standard_False;
}
+//==================================================
+// Function: Matches
+// Purpose :
+//==================================================
+
Standard_Boolean Select3D_SensitivePoint::
Matches (const Standard_Real XMin,
- const Standard_Real YMin,
- const Standard_Real XMax,
- const Standard_Real YMax,
- const Standard_Real aTol)
+ const Standard_Real YMin,
+ const Standard_Real XMax,
+ const Standard_Real YMax,
+ const Standard_Real aTol)
{
Bnd_Box2d B;
B.Update(Min(XMin,XMax),Min(YMin,YMax),Max(XMin,XMax),Max(YMin,YMax));
return !B.IsOut(myprojpt);
}
-
//=======================================================================
//function : Matches
//purpose :
Standard_Boolean Select3D_SensitivePoint::
Matches (const TColgp_Array1OfPnt2d& aPoly,
- const Bnd_Box2d& aBox,
- const Standard_Real aTol)
+ const Bnd_Box2d& aBox,
+ const Standard_Real aTol)
{
Standard_Real Umin,Vmin,Umax,Vmax;
aBox.Get(Umin,Vmin,Umax,Vmax);
return Standard_False;
}
-
-
//=======================================================================
//function : Point
//purpose :
//=======================================================================
+
gp_Pnt Select3D_SensitivePoint::Point() const
{return mypoint;}
return NiouEnt;
}
-
//=======================================================================
//function : Dump
//purpose :
{
return ElCLib::Parameter(EyeLine,mypoint);
}
-
-
---Level: Public
---Purpose: Constructs the sensitive circle object defined by the
-- 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;
---Level: Public
mypolyg2d : Address from Standard is protected;
mybox2d : Box2d from Select3D is protected;
mynbpoints : Integer from Standard is protected;
-end SensitiveFace;
+end SensitivePoly;
Select3D_SensitivePoly::
Select3D_SensitivePoly(const Handle(SelectBasics_EntityOwner)& OwnerId,
- const TColgp_Array1OfPnt& ThePoints):
+ const TColgp_Array1OfPnt& ThePoints):
Select3D_SensitiveEntity(OwnerId)
{
mynbpoints = ThePoints.Upper()-ThePoints.Lower()+1;
}
//==================================================
-// Function:
+// Function: Creation
// Purpose :
//==================================================
Select3D_SensitivePoly::
Select3D_SensitivePoly(const Handle(SelectBasics_EntityOwner)& OwnerId,
- const Handle(TColgp_HArray1OfPnt)& ThePoints):
+ const Handle(TColgp_HArray1OfPnt)& ThePoints):
Select3D_SensitiveEntity(OwnerId)
{
mynbpoints = ThePoints->Upper()-ThePoints->Lower()+1;
}
//==================================================
-// Function:
+// Function: Creation
// Purpose :
//==================================================
Select3D_SensitivePoly::
Select3D_SensitivePoly(const Handle(SelectBasics_EntityOwner)& OwnerId,
- const Standard_Integer NbPoints):
+ const Standard_Integer NbPoints):
Select3D_SensitiveEntity(OwnerId)
{
mynbpoints = NbPoints;
}
//==================================================
-// Function:
+// Function: Project
// Purpose :
//==================================================
}
//==================================================
-// Function:
+// Function: Areas
// Purpose :
//==================================================
void Select3D_SensitivePoly
}
//==================================================
-// Function:
+// Function: Destroy
// Purpose :
//==================================================
void Select3D_SensitivePoly::Destroy()
// Purpose :Constructor
//=====================================================
-
Select3D_SensitiveSegment::
-Select3D_SensitiveSegment(const Handle(SelectBasics_EntityOwner)& OwnerId,
- const gp_Pnt& FirstP,
- const gp_Pnt& LastP,
- const Standard_Integer MaxRect):
+Select3D_SensitiveSegment(const Handle(SelectBasics_EntityOwner)& OwnerId,
+ const gp_Pnt& FirstP,
+ const gp_Pnt& LastP,
+ const Standard_Integer MaxRect):
Select3D_SensitiveEntity(OwnerId),
mymaxrect(MaxRect)
{
// Function :
// Purpose :
//=====================================================
+
void Select3D_SensitiveSegment
::Project(const Handle(Select3D_Projector)& aProj)
{
gp_Pnt2d aPoint2dStart;
gp_Pnt2d aPoint2dEnd;
- if(HasLocation()){
+ if(HasLocation())
+ {
gp_Pnt aStart(mystart.x, mystart.y, mystart.z);
gp_Pnt aEnd(myend.x, myend.y, myend.z);
aProj->Project(aStart.Transformed(Location().Transformation()),aPoint2dStart);
aProj->Project(aEnd.Transformed(Location().Transformation()),aPoint2dEnd);
}
- else{
+ else
+ {
aProj->Project(mystart,aPoint2dStart);
aProj->Project(myend,aPoint2dEnd);
}
// Function : Areas
// Purpose :
//=====================================================
+
void Select3D_SensitiveSegment
::Areas(SelectBasics_ListOfBox2d& theareas)
{
// gp_Dir2d dy (0.,1.);
gp_Pnt2d aPStart(myprojstart.x,myprojstart.y);
- if(aPStart.Distance(myprojend)<=Precision::Confusion()){
+ if(aPStart.Distance(myprojend)<=Precision::Confusion())
+ {
Bnd_Box2d curbox;
curbox.Set(myprojstart);
theareas.Append(curbox);
- }
- else {
+ }
+ else
+ {
gp_Vec2d MyVec(myprojstart,myprojend);//,VAxx(gp_Dir2d(0.,1.));
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/12. && theangle <=5*M_PI/12.)
- {
- TColgp_Array1OfPnt2d BoxPoint (1,mymaxrect+1);
- BoxPoint (1) = myprojstart;
- BoxPoint(mymaxrect+1)=myprojend;
- gp_Vec2d Vtr = MyVec/mymaxrect;
-// for (Standard_Integer i=2;i<=mymaxrect;i++)
- Standard_Integer i;
- for ( i=2;i<=mymaxrect;i++)
- {BoxPoint (i) = BoxPoint (i-1).Translated(Vtr);}
- for (i=2;i<=mymaxrect+1;i++)
- { Bnd_Box2d curbox;
- curbox.Set(BoxPoint(i-1));
- curbox.Add(BoxPoint(i));
- theareas.Append(curbox);
- }
+ {
+ TColgp_Array1OfPnt2d BoxPoint (1,mymaxrect+1);
+ BoxPoint (1) = myprojstart;
+ BoxPoint(mymaxrect+1)=myprojend;
+ gp_Vec2d Vtr = MyVec/mymaxrect;
+ Standard_Integer i;
+ for ( i=2;i<=mymaxrect;i++)
+ {
+ BoxPoint (i) = BoxPoint (i-1).Translated(Vtr);
+ }
+ for (i=2;i<=mymaxrect+1;i++)
+ {
+ Bnd_Box2d curbox;
+ curbox.Set(BoxPoint(i-1));
+ curbox.Add(BoxPoint(i));
+ theareas.Append(curbox);
+ }
}
else
- {
- Bnd_Box2d curbox;
- curbox.Set(myprojstart);
- curbox.Add(myprojend);
- theareas.Append(curbox);
+ {
+ Bnd_Box2d curbox;
+ curbox.Set(myprojstart);
+ curbox.Add(myprojend);
+ theareas.Append(curbox);
}
}
}
// Function : Matches
// Purpose :
//=====================================================
+
Standard_Boolean Select3D_SensitiveSegment
::Matches(const Standard_Real X,
- const Standard_Real Y,
- const Standard_Real aTol,
- Standard_Real& DMin)
+ const Standard_Real Y,
+ const Standard_Real aTol,
+ Standard_Real& DMin)
{
gp_Pnt2d aPStart(myprojstart.x,myprojstart.y);
gp_Pnt2d aPEnd(myprojend.x,myprojend.y);
return Select3D_SensitiveEntity::Matches (X, Y, aTol, DMin); // compute and validate depth
}
+//=====================================================
+// Function : Matches
+// Purpose :
+//=====================================================
+
Standard_Boolean Select3D_SensitiveSegment::
Matches (const Standard_Real XMin,
- const Standard_Real YMin,
- const Standard_Real XMax,
- const Standard_Real YMax,
- const Standard_Real aTol)
+ const Standard_Real YMin,
+ const Standard_Real XMax,
+ const Standard_Real YMax,
+ const Standard_Real aTol)
{
Bnd_Box2d BoundBox;
BoundBox.Update(XMin-aTol,YMin-aTol,XMax+aTol,YMax+aTol);
return Standard_True;
}
-
//=======================================================================
//function : Matches
//purpose :
Standard_Boolean Select3D_SensitiveSegment::
Matches (const TColgp_Array1OfPnt2d& aPoly,
- const Bnd_Box2d& aBox,
- const Standard_Real aTol)
+ const Bnd_Box2d& aBox,
+ const Standard_Real aTol)
{
Standard_Real Umin,Vmin,Umax,Vmax;
aBox.Get(Umin,Vmin,Umax,Vmax);
//function : GetConnected
//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());
NiouEnt->UpdateLocation(aLoc);
return NiouEnt;
XY from gp,
Pnt from gp,
TypeOfSensitivity from Select3D,
- Location from TopLoc
+ Location from TopLoc,
+ SensitiveEntity from Select3D
is
Create (OwnerId : EntityOwner from SelectBasics;
returns mutable SensitiveTriangle;
---Level: Public
---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;
X,Y : Real from Standard;
Dmin : out Real from Standard) returns Integer from Standard;
---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
}
//==================================================
-// Function:
+// Function: Creation
// Purpose :
//==================================================
Select3D_SensitiveTriangle::
Select3D_SensitiveTriangle(const Handle(SelectBasics_EntityOwner)& OwnerId,
- const gp_Pnt& P0,
- const gp_Pnt& P1,
- const gp_Pnt& P2,
- const Select3D_TypeOfSensitivity aType):
+ const gp_Pnt& P0,
+ const gp_Pnt& P1,
+ const gp_Pnt& P2,
+ const Select3D_TypeOfSensitivity aType):
Select3D_SensitivePoly(OwnerId,3),
mytype (aType)
{
}
//==================================================
-// Function:
+// Function: Matches
// Purpose :
//==================================================
Standard_Boolean Select3D_SensitiveTriangle::
-Matches(const Standard_Real X,
- const Standard_Real Y,
- const Standard_Real aTol,
- Standard_Real& DMin)
+Matches(const Standard_Real X,
+ const Standard_Real Y,
+ const Standard_Real aTol,
+ Standard_Real& DMin)
{
Select3D_SensitiveEntity::Matches(X,Y,aTol,DMin);
if(Bnd_Box2d(mybox2d).IsOut(gp_Pnt2d(X,Y))) return Standard_False;
Standard_Integer Res;
- switch (mytype){
+ switch (mytype)
+ {
case Select3D_TOS_BOUNDARY:
Res = Status(X,Y,aTol,DMin);
return Res== 1;
return Standard_True;
}
+//==================================================
+// Function: Matches
+// Purpose :
+//==================================================
+
Standard_Boolean Select3D_SensitiveTriangle::
Matches (const Standard_Real XMin,
- const Standard_Real YMin,
- const Standard_Real XMax,
- const Standard_Real YMax,
- const Standard_Real aTol)
+ const Standard_Real YMin,
+ const Standard_Real XMax,
+ const Standard_Real YMax,
+ const Standard_Real aTol)
{
Bnd_Box2d B;
B.Update(Min(XMin,XMax)-aTol,
- Min(YMin,YMax)-aTol,
- Max(XMin,XMax)+aTol,
- Max(YMin,YMax)+aTol);
- for(Standard_Integer i=0;i<=2;i++){
+ Min(YMin,YMax)-aTol,
+ Max(XMin,XMax)+aTol,
+ Max(YMin,YMax)+aTol);
+ for(Standard_Integer i=0;i<=2;i++)
+ {
if(B.IsOut(((Select3D_Pnt2d*)mypolyg2d)[i]))
- return Standard_False;}
+ return Standard_False;
+ }
return Standard_True;
}
-
//=======================================================================
//function : Matches
//purpose :
Standard_Boolean Select3D_SensitiveTriangle::
Matches (const TColgp_Array1OfPnt2d& aPoly,
- const Bnd_Box2d& aBox,
- const Standard_Real aTol)
+ const Bnd_Box2d& aBox,
+ const Standard_Real aTol)
{
Standard_Real Umin,Vmin,Umax,Vmax;
aBox.Get(Umin,Vmin,Umax,Vmax);
Tolv = 1e-7;
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]);
if(RES!=1) return Standard_False;
}
return Standard_True;
}
-
+//==================================================
+// Function: Points3D
+// Purpose :
+//==================================================
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_XYZ CDG(((Select3D_Pnt*)mypolyg3d)[0]);
CDG += ((Select3D_Pnt*)mypolyg3d)[2];
CDG /=3.;
return gp_Pnt(CDG);;
-}
+}
+
+//==================================================
+// Function: Center2D
+// Purpose :
+//==================================================
gp_XY Select3D_SensitiveTriangle::Center2D() const
{
//=======================================================================
Standard_Integer Select3D_SensitiveTriangle::Status(const Standard_Real X,
- const Standard_Real Y,
- const Standard_Real aTol,
- Standard_Real& DMin) const
-{
-
+ const Standard_Real Y,
+ const Standard_Real aTol,
+ Standard_Real& DMin) const
+{
return Status(((Select3D_Pnt2d*)mypolyg2d)[0],((Select3D_Pnt2d*)mypolyg2d)[1],
((Select3D_Pnt2d*)mypolyg2d)[2],gp_XY(X,Y),aTol,DMin);
-
}
-
//=======================================================================
//function : Status
//purpose :
//=======================================================================
Standard_Integer Select3D_SensitiveTriangle::Status(const gp_XY& p0,
- const gp_XY& p1,
- const gp_XY& p2,
- const gp_XY& TheP,
- const Standard_Real aTol,
- Standard_Real& DMin)
+ const gp_XY& p1,
+ const gp_XY& p2,
+ const gp_XY& TheP,
+ const Standard_Real aTol,
+ Standard_Real& DMin)
{
-
Bnd_Box2d B;
B.Update(p0.X(),p0.Y());B.Update(p1.X(),p1.Y());B.Update(p2.X(),p2.Y());
B.Enlarge(aTol);
DMin = ( aD < 0 ? -aD : 0. );
return 0;
}
-
+
//=======================================================================
//function : Dump
//purpose :
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;
- if(FullDump){
+ if(FullDump)
+ {
S<<"\t\tProjected Points"<<endl;
S<<"\t\t 0.[ "<<COORD2d(0,x)<<" , "<<COORD2d(0,y)<<" ]"<<endl;
S<<"\t\t 2.[ "<<COORD2d(2,x)<<" , "<<COORD2d(2,y)<<" ]"<<endl;
// S<<"\t\t\tOwner:"<<myOwnerId<<endl;
Select3D_SensitiveEntity::DumpBox(S,mybox2d);
-
}
}
+
//=======================================================================
//function : ComputeDepth
//purpose :
//=======================================================================
+
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 P2(((Select3D_Pnt*)mypolyg3d)[1].x, ((Select3D_Pnt*)mypolyg3d)[1].y, ((Select3D_Pnt*)mypolyg3d)[1].z);
- gp_Pnt P3(((Select3D_Pnt*)mypolyg3d)[2].x, ((Select3D_Pnt*)mypolyg3d)[2].y, ((Select3D_Pnt*)mypolyg3d)[2].z);
+ gp_Pnt P1 = ((Select3D_Pnt*)mypolyg3d)[0];
+ gp_Pnt P2 = ((Select3D_Pnt*)mypolyg3d)[1];
+ gp_Pnt P3 = ((Select3D_Pnt*)mypolyg3d)[2];
gp_Trsf TheTrsf ;
if(HasLocation())
TheTrsf = Location().Transformation();
- if(TheTrsf.Form()!=gp_Identity){
+ if(TheTrsf.Form()!=gp_Identity)
+ {
P1.Transform(TheTrsf);
P2.Transform(TheTrsf);
P3.Transform(TheTrsf);
if(Abs(val2)>Precision::Confusion())
prof =val1/val2;
- if (prof==Precision::Infinite()){
+ if (prof==Precision::Infinite())
+ {
prof= ElCLib::Parameter(EyeLine,P1);
prof = Min (prof, ElCLib::Parameter(EyeLine,P2));
prof = Min (prof, ElCLib::Parameter(EyeLine,P3));
}
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;
+}
\ No newline at end of file
// }
static Standard_Boolean S3D_IsEdgeIn(const Standard_Integer e1,
- const Standard_Integer e2,
- const Standard_Integer N1,
- const Standard_Integer N2,
- const Standard_Integer N3)
+ const Standard_Integer e2,
+ const Standard_Integer N1,
+ const Standard_Integer N2,
+ const Standard_Integer N3)
{
Standard_Integer bid1 = (e1 == N1) ? N1 : ((e1 == N2) ? N2 : ( e1==N3 ? N3 : 0));
if(bid1==0) return Standard_False;
return Standard_True;
}
-
-
//=======================================================================
//function : Select3D_SensitiveTriangulation
//purpose :
//=======================================================================
Select3D_SensitiveTriangulation::
-Select3D_SensitiveTriangulation(const Handle(SelectBasics_EntityOwner)& OwnerId,
- const Handle(Poly_Triangulation)& Trg,
- const TopLoc_Location& Loc,
- const Standard_Boolean InteriorFlag):
- Select3D_SensitiveEntity(OwnerId),
+Select3D_SensitiveTriangulation(const Handle(SelectBasics_EntityOwner)& OwnerId,
+ const Handle(Poly_Triangulation)& Trg,
+ const TopLoc_Location& Loc,
+ const Standard_Boolean InteriorFlag):
+Select3D_SensitiveEntity(OwnerId),
myTriangul(Trg),
myiniloc(Loc),
myIntFlag(InteriorFlag),
Standard_Integer n[3];
// to find connections in case when the border is not concerned...
- if(!myIntFlag){
+ if(!myIntFlag)
+ {
myFreeEdges = new TColStd_HArray1OfInteger(1,2*S3D_NumberOfFreeEdges(Trg));
TColStd_Array1OfInteger& FreeE = myFreeEdges->ChangeArray1();
Poly_Connect pc(myTriangul);
Standard_Integer t[3];
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]);
triangles(i).Get(n[0],n[1],n[2]);
cdg += (Nodes(n[0]).XYZ() + Nodes(n[1]).XYZ()+ Nodes(n[2]).XYZ())/3.;
- for (j = 0; j < 3; j++) {
- Standard_Integer k = (j+1) % 3;
- if (t[j] == 0) {
- FreeE(fr) = n[j];
- FreeE(fr+1)= n[k];
- fr += 2;
- }
+ for (j = 0; j < 3; j++)
+ {
+ Standard_Integer k = (j+1) % 3;
+ if (t[j] == 0)
+ {
+ FreeE(fr) = n[j];
+ FreeE(fr+1)= n[k];
+ fr += 2;
+ }
}
}
}
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]);
cdg += (Nodes(n[0]).XYZ() + Nodes(n[1]).XYZ()+ Nodes(n[2]).XYZ())/3.;
}
}
-
if(nbTriangles!=0) cdg /= nbTriangles;
myCDG3D = gp_Pnt(cdg);
//function : Select3D_SensitiveTriangulation
//purpose :
//=======================================================================
+
Select3D_SensitiveTriangulation::
-Select3D_SensitiveTriangulation(const Handle(SelectBasics_EntityOwner)& OwnerId,
- const Handle(Poly_Triangulation)& Trg,
- const TopLoc_Location& Loc,
- const Handle(TColStd_HArray1OfInteger)& FreeEdges,
- const gp_Pnt& TheCDG,
- const Standard_Boolean InteriorFlag):
+Select3D_SensitiveTriangulation(const Handle(SelectBasics_EntityOwner)& OwnerId,
+ const Handle(Poly_Triangulation)& Trg,
+ const TopLoc_Location& Loc,
+ const Handle(TColStd_HArray1OfInteger)& FreeEdges,
+ const gp_Pnt& TheCDG,
+ const Standard_Boolean InteriorFlag):
Select3D_SensitiveEntity(OwnerId),
myTriangul(Trg),
myiniloc(Loc),
myDetectedTr(-1)
{
}
+
//=======================================================================
//function : Project
//purpose :
//function : Matches
//purpose :
//=======================================================================
-Standard_Boolean Select3D_SensitiveTriangulation::Matches(const Standard_Real X,
- const Standard_Real Y,
- const Standard_Real aTol,
- Standard_Real& DMin)
+Standard_Boolean Select3D_SensitiveTriangulation::
+Matches(const Standard_Real X,
+ const Standard_Real Y,
+ const Standard_Real aTol,
+ Standard_Real& DMin)
{
// get view direction (necessary for calculation of depth) from field mylastprj of the base class
if (mylastprj.IsNull())
//purpose :
//=======================================================================
-Standard_Boolean Select3D_SensitiveTriangulation::Matches(const Standard_Real XMin,
- const Standard_Real YMin,
- const Standard_Real XMax,
- const Standard_Real YMax,
- const Standard_Real aTol)
+Standard_Boolean Select3D_SensitiveTriangulation::
+Matches(const Standard_Real XMin,
+ const Standard_Real YMin,
+ const Standard_Real XMax,
+ const Standard_Real YMax,
+ const Standard_Real aTol)
{
Bnd_Box2d B;
B.Update(Min(XMin,XMax)-aTol,
- Min(YMin,YMax)-aTol,
- Max(XMin,XMax)+aTol,
- Max(YMin,YMax)+aTol);
+ Min(YMin,YMax)-aTol,
+ Max(XMin,XMax)+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)))
return Standard_False;
}
return Standard_True;
}
-
//=======================================================================
//function : Matches
//purpose :
Standard_Boolean Select3D_SensitiveTriangulation::
Matches (const TColgp_Array1OfPnt2d& aPoly,
- const Bnd_Box2d& aBox,
- const Standard_Real aTol)
+ const Bnd_Box2d& aBox,
+ const Standard_Real aTol)
{
Standard_Real Umin,Vmin,Umax,Vmax;
aBox.Get(Umin,Vmin,Umax,Vmax);
Tolv = 1e-7;
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));
if(RES!=1) return Standard_False;
}
return Standard_True;
}
+//=======================================================================
+//function : Status
+//purpose :
+//=======================================================================
-
-Standard_Integer Select3D_SensitiveTriangulation::Status (const gp_XY& TheP,
- const gp_XY& Proj0,
- const gp_XY& Proj1,
- const gp_XY& Proj2,
- const Standard_Real aTol,
- Standard_Real& DD) const
+Standard_Integer Select3D_SensitiveTriangulation::
+Status (const gp_XY& TheP,
+ const gp_XY& Proj0,
+ const gp_XY& Proj1,
+ const gp_XY& Proj2,
+ const Standard_Real aTol,
+ Standard_Real& DD) const
{
return Select3D_SensitiveTriangle::Status(Proj0,Proj1,Proj2,TheP,aTol,DD);
}
//=======================================================================
Standard_Boolean Select3D_SensitiveTriangulation::IsFree(const Standard_Integer IndexOfTriangle,
- Standard_Integer& FoundIndex) const
+ Standard_Integer& FoundIndex) const
{
-
FoundIndex=-1;
Standard_Integer n[3];
const Poly_Array1OfTriangle& triangles = myTriangul->Triangles();
triangles(IndexOfTriangle).Get(n[0],n[1],n[2]);
- TColStd_Array1OfInteger& FreeE = myFreeEdges->ChangeArray1();
-
- for(Standard_Integer I=1;I<=FreeE.Length() && FoundIndex==-1;I+=2){
+ TColStd_Array1OfInteger& FreeE = myFreeEdges->ChangeArray1();
- if(FreeE(I) == n[0]){
-
- if(FreeE(I+1)== n[1] || FreeE(I+1)== n[2]) FoundIndex=I;}
- else if(FreeE(I) == n[1]){
- 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;}
+ for(Standard_Integer I=1;I<=FreeE.Length() && FoundIndex==-1;I+=2)
+ {
+ if(FreeE(I) == n[0])
+ {
+ if(FreeE(I+1)== n[1] || FreeE(I+1)== n[2])
+ FoundIndex=I;
+ }
+ else if(FreeE(I) == n[1])
+ {
+ 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;
//function : GetConnected
//purpose :
//=======================================================================
+
Handle(Select3D_SensitiveEntity) Select3D_SensitiveTriangulation::
GetConnected(const TopLoc_Location& aLoc)
{
-
Handle(Select3D_SensitiveTriangulation) NiouEnt =
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;
// if(!TheLocToApply.IsIdentity())
NiouEnt->UpdateLocation(aLoc);
-
return NiouEnt;
}
-
//=======================================================================
//function : ResetLocation
//purpose :
//=======================================================================
+
void Select3D_SensitiveTriangulation::ResetLocation()
{
Select3D_SensitiveEntity::ResetLocation();
ComputeTotalTrsf();
}
+
+//=======================================================================
+//function : SetLocation
+//purpose :
+//=======================================================================
+
void Select3D_SensitiveTriangulation::SetLocation(const TopLoc_Location& aLoc)
{
Select3D_SensitiveEntity::SetLocation(aLoc);
S<<"\t\tNb Nodes : "<<myTriangul->NbNodes()<<endl;
S<<"\t\tNb Free Edges: "<<myFreeEdges->Length()/2<<endl;
- if(FullDump){
+ if(FullDump)
+ {
// S<<"\t\t\tOwner:"<<myOwnerId<<endl;
Select3D_SensitiveEntity::DumpBox(S,mybox2d);
}
//function : ComputeDepth
//purpose :
//=======================================================================
+
Standard_Real Select3D_SensitiveTriangulation::ComputeDepth(const gp_Lin& EyeLine) const
{
if(myDetectedTr==-1) return Precision::Infinite(); // currently not implemented...
triangles(myDetectedTr).Get(n1,n2,n3);
gp_Pnt P[3]={Nodes(n1),Nodes(n2),Nodes(n3)};
- if(myTrsf.Form()!=gp_Identity){
- for(Standard_Integer i =0;i<=2;i++){
+ if(myTrsf.Form()!=gp_Identity)
+ {
+ for(Standard_Integer i =0;i<=2;i++)
+ {
P[i].Transform(myTrsf);
}
}
#endif
// 3 pts mixed...
- if(SingularCase ==2){
+ if(SingularCase ==2)
+ {
prof= ElCLib::Parameter(EyeLine,P[0]);
return prof;
}
gp_Vec OPo(Oye,P[0]);
// 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 Det = Dir^V;
gp_Vec VSM = OPo^V;
else if(Det.Z()> Precision::Confusion())
prof = VSM.Z()/Det.Z();
}
- else{
-
+ else
+ {
Standard_Real val1 = OPo.DotCross(Vtr[0],Vtr[2]);
Standard_Real val2 = Dir.DotCross(Vtr[0],Vtr[2]);
if(Abs(val2)>Precision::Confusion())
prof =val1/val2;
}
- if (prof==Precision::Infinite()){
+ if (prof==Precision::Infinite())
+ {
prof= ElCLib::Parameter(EyeLine,P[0]);
prof = Min (prof, ElCLib::Parameter(EyeLine,P[1]));
prof = Min (prof, ElCLib::Parameter(EyeLine,P[2]));
//function : DetectedTriangle
//purpose :
//=======================================================================
-Standard_Boolean Select3D_SensitiveTriangulation::DetectedTriangle(gp_Pnt& P1,
- gp_Pnt& P2,
- gp_Pnt& P3) const
+
+Standard_Boolean Select3D_SensitiveTriangulation::
+DetectedTriangle(gp_Pnt& P1,
+ gp_Pnt& P2,
+ gp_Pnt& P3) const
{
if(myDetectedTr==-1) return Standard_False; // currently not implemented...
const Poly_Array1OfTriangle& triangles = myTriangul->Triangles();
P1 = Nodes(n1);
P2 = Nodes(n2);
P3 = Nodes(n3);
- if(myTrsf.Form()!=gp_Identity){
+ if(myTrsf.Form()!=gp_Identity)
+ {
P1.Transform(myTrsf);
P2.Transform(myTrsf);
P3.Transform(myTrsf);
// Function : DetectedTriangle2d
// 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)
return Standard_False; // currently not implemented...
}
else
return Standard_False;
-
}
+//=============================================================================
+// Function : ComputeTotalTrsf
+// Purpose :
+//=============================================================================
+
void Select3D_SensitiveTriangulation::ComputeTotalTrsf()
{
Standard_Boolean hasloc = (HasLocation() || !myiniloc.IsIdentity());
- if(hasloc){
+ if(hasloc)
+ {
if(myiniloc.IsIdentity())
myTrsf = Location().Transformation();
- else if(HasLocation()){
+ else if(HasLocation())
+ {
myTrsf = (Location()*myiniloc).Transformation();
}
else
myTrsf = myiniloc.Transformation();
}
- else{
+ else
+ {
gp_Trsf TheId;
myTrsf = TheId;
}
---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;
// Purpose :Constructor
//=====================================================
-
Select3D_SensitiveWire::
Select3D_SensitiveWire(const Handle(SelectBasics_EntityOwner)& OwnerId,
- const Standard_Integer MaxRect):
+ const Standard_Integer MaxRect):
Select3D_SensitiveEntity(OwnerId),
mymaxrect(MaxRect),
myDetectedIndex(-1)
// Function : Add
// Purpose :
//=====================================================
+
void Select3D_SensitiveWire
::Add(const Handle(Select3D_SensitiveEntity)& aSensitive)
{
- if ( !aSensitive .IsNull()) {
- if(!HasLocation())
- mysensitive.Append(aSensitive);
- else
- mysensitive.Append(aSensitive->GetConnected(Location()));
-
- }
+ if(!aSensitive.IsNull())
+ mysensitive.Append(aSensitive);
}
//=======================================================================
Select3D_SensitiveEntity::SetLocation(aLoc);
for(Standard_Integer i=1;i<=mysensitive.Length();i++){
if(mysensitive(i)->HasLocation()){
- if(mysensitive(i)->Location()!=aLoc)
- mysensitive(i)->SetLocation(mysensitive(i)->Location()*aLoc);
+ if(mysensitive(i)->Location()!=aLoc)
+ mysensitive(i)->SetLocation(mysensitive(i)->Location()*aLoc);
}
else
mysensitive(i)->SetLocation(aLoc);
}
}
+
//=======================================================================
//function : ResetLocation
//purpose :
}
Select3D_SensitiveEntity::ResetLocation();
}
+
//=====================================================
// Function : Project
// Purpose :
void Select3D_SensitiveWire
::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);
Select3D_SensitiveEntity::Project(aProj);
}
// Function : Areas
// Purpose :
//=====================================================
+
void Select3D_SensitiveWire
::Areas(SelectBasics_ListOfBox2d& theareas)
{
BB.Add(it.Value());
theareas.Append(BB);
-
}
//=====================================================
//=====================================================
Standard_Boolean Select3D_SensitiveWire
::Matches(const Standard_Real X,
- const Standard_Real Y,
- const Standard_Real aTol,
- Standard_Real& DMin)
+ const Standard_Real Y,
+ const Standard_Real aTol,
+ Standard_Real& DMin)
{
Standard_Integer i;
Standard_Real Dcur;
DMin = Precision::Infinite();
Standard_Boolean IsTouched = Standard_False;
- for (i=1; i<=mysensitive.Length(); i++) {
- if (mysensitive.Value(i)->Matches(X,Y,aTol,Dcur)) {
+ for (i=1; i<=mysensitive.Length(); i++)
+ {
+ if (mysensitive.Value(i)->Matches(X,Y,aTol,Dcur))
+ {
IsTouched = Standard_True;
- if(Dcur<=DMin){
- myDetectedIndex = i;
- DMin = Dcur;
+ if(Dcur<=DMin)
+ {
+ myDetectedIndex = i;
+ DMin = Dcur;
}
}
}
// Function : Matches
// Purpose :
//=====================================================
- Standard_Boolean Select3D_SensitiveWire::
+
+Standard_Boolean Select3D_SensitiveWire::
Matches (const Standard_Real XMin,
- const Standard_Real YMin,
- const Standard_Real XMax,
- const Standard_Real YMax,
- const Standard_Real aTol)
+ const Standard_Real YMin,
+ const Standard_Real XMax,
+ const Standard_Real YMax,
+ const Standard_Real aTol)
{
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)))
return Standard_False;
}
Standard_Boolean Select3D_SensitiveWire::
Matches (const TColgp_Array1OfPnt2d& aPoly,
- const Bnd_Box2d& aBox,
- const Standard_Real aTol)
+ const Bnd_Box2d& aBox,
+ const Standard_Real aTol)
{
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)))
return Standard_False;
}
// Function : MaxBoxes
// Purpose :
//=====================================================
+
Standard_Integer Select3D_SensitiveWire::
MaxBoxes () const
{
//function : GetConnected
//purpose :
//=======================================================================
+
Handle(Select3D_SensitiveEntity) Select3D_SensitiveWire::GetConnected(const TopLoc_Location& aLoc)
{
Handle(Select3D_SensitiveWire) SWIR = new Select3D_SensitiveWire(myOwnerId);
for(Standard_Integer i=1;i<=mysensitive.Length();i++)
- SWIR->Add(mysensitive(i));
+ SWIR->Add(mysensitive(i)->GetConnected(aLoc));
if(HasLocation())
SWIR->SetLocation(Location()*aLoc);
//function : ComputeDepth
//purpose :
//=======================================================================
+
Standard_Real Select3D_SensitiveWire::ComputeDepth(const gp_Lin& EyeLine) const
{
//function : SetLastPrj
//purpose :
//=======================================================================
+
void Select3D_SensitiveWire::SetLastPrj(const Handle(Select3D_Projector)& Prj)
{
Select3D_SensitiveEntity::SetLastPrj(Prj);
//function : GetEdges
//purpose : returns the sensitive edges stored in this wire
//=======================================================================
+
void Select3D_SensitiveWire::GetEdges( Select3D_SensitiveEntitySequence& theEdges )
{
theEdges.Clear();
// Function : GetLastDetected
// Purpose :
//=============================================================================
+
Handle(Select3D_SensitiveEntity) Select3D_SensitiveWire::GetLastDetected() const
{
Handle(Select3D_SensitiveEntity) 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);
+ }
+}
aSensitivityFactor : ShortReal from Standard =1);
- Set (me:mutable ; TheOwnerId : EntityOwner) is static;
+ Set (me:mutable ; TheOwnerId : EntityOwner) is virtual;
---Level: Public
#include <SelectMgr_Selection.hxx>
#include <StdFail_NotDone.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
#include <strings.h>
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
//purpose :
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' }] ]",
__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);
}