diff --git a/src/AIS/AIS_ConnectedInteractive.cdl b/src/AIS/AIS_ConnectedInteractive.cdl index 92267572fd..f4492ffd9a 100755 --- a/src/AIS/AIS_ConnectedInteractive.cdl +++ b/src/AIS/AIS_ConnectedInteractive.cdl @@ -15,7 +15,13 @@ -- 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 @@ -140,14 +146,9 @@ is 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; diff --git a/src/AIS/AIS_ConnectedInteractive.cxx b/src/AIS/AIS_ConnectedInteractive.cxx index 71e3280e66..84f848ec08 100755 --- a/src/AIS/AIS_ConnectedInteractive.cxx +++ b/src/AIS/AIS_ConnectedInteractive.cxx @@ -137,39 +137,39 @@ void AIS_ConnectedInteractive::Compute(const Handle_PrsMgr_PresentationManager2d //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 "<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 "< #include #include +#include +#include //======================================================================= //function : AIS_ConnectedShape @@ -159,27 +161,22 @@ void AIS_ConnectedShape::Compute(const Handle_PrsMgr_PresentationManager2d& aPre 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... //======================================================================= - -void AIS_ConnectedShape::ComputeSelection (const Handle(SelectMgr_Selection)& aSelection, - const Standard_Integer aMode) +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) +{ + typedef NCollection_List SensitiveList; + typedef NCollection_DataMap Shapes2EntitiesMap; + UpdateShape(); aSelection->Clear(); // It is checked if there is nothing to do with the reference @@ -187,79 +184,76 @@ void AIS_ConnectedShape::ComputeSelection (const Handle(SelectMgr_Selection)& aS if(!myReference->HasSelection(aMode)) 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; + Handle(StdSelect_BRepOwner) anOwner; + TopLoc_Location aBidLoc; + Handle(Select3D_SensitiveEntity) aSE, aNewSE; + Shapes2EntitiesMap aShapes2EntitiesMap; + SensitiveList aSEList; + TopoDS_Shape aSubShape; - switch(TheType){ - case TopAbs_VERTEX: - case TopAbs_EDGE: - case TopAbs_WIRE: - case TopAbs_FACE: - case TopAbs_SHELL: + // 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; - } - - case TopAbs_SHAPE: - default: - { - // In case if there is only one owner of the set of - // sensible primitives... - OWNR = new StdSelect_BRepOwner(myOwnSh,this); - Standard_Boolean FirstIncr(Standard_True); - for(RefSel->Init();RefSel->More();RefSel->Next()){ - SE = *((Handle(Select3D_SensitiveEntity)*) &(RefSel->Sensitive())); - if(FirstIncr){ - Standard_Integer Prior = SE->OwnerId()->Priority(); - Handle(SelectBasics_EntityOwner)::DownCast(OWNR)->Set(Prior); - FirstIncr = Standard_False;} - - if(myLocation.IsIdentity()) - NiouSE = SE->GetConnected(BidLoc); - else - NiouSE = SE->GetConnected(myLocation); - NiouSE->Set(OWNR); - aSelection->Add(NiouSE); - } - break; } } - StdSelect::SetDrawerForBRepOwner(aSelection,myDrawer); - + + // Fill in selection from aShapes2EntitiesMap + Shapes2EntitiesMap::Iterator aMapIt(aShapes2EntitiesMap); + for(; aMapIt.More(); aMapIt.Next()) + { + aSEList = aMapIt.Value(); + anOwner = new StdSelect_BRepOwner(aMapIt.Key(), + this, + aSEList.First()->OwnerId()->Priority(), + Standard_True); + + SensitiveList::Iterator aListIt(aSEList); + for(; aListIt.More(); aListIt.Next()) + { + aSE = aListIt.Value(); + if(myLocation.IsIdentity()) + { + aNewSE = aSE->GetConnected(aBidLoc); + aNewSE->Set(anOwner); + // In case if aSE caches some location-dependent data + // that must be updated after setting anOwner + aNewSE->SetLocation(aBidLoc); + } + else + { + aNewSE = aSE->GetConnected(myLocation); + aNewSE->Set(anOwner); + // In case if aSE caches some location-dependent data + // that must be updated after setting anOwner + aNewSE->SetLocation(myLocation); + } + aSelection->Add(aNewSE); + } + } + + StdSelect::SetDrawerForBRepOwner(aSelection,myDrawer); } - //======================================================================= //function : Shape diff --git a/src/OpenGl/OpenGl_togl_begin_immediat_mode.cxx b/src/OpenGl/OpenGl_togl_begin_immediat_mode.cxx index 4351e3da67..79c626b275 100755 --- a/src/OpenGl/OpenGl_togl_begin_immediat_mode.cxx +++ b/src/OpenGl/OpenGl_togl_begin_immediat_mode.cxx @@ -899,7 +899,7 @@ call_togl_draw_structure /*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); } } } diff --git a/src/Select3D/Select3D_SensitiveBox.cxx b/src/Select3D/Select3D_SensitiveBox.cxx index 0a8115fdea..f20fae6368 100755 --- a/src/Select3D/Select3D_SensitiveBox.cxx +++ b/src/Select3D/Select3D_SensitiveBox.cxx @@ -20,11 +20,10 @@ //================================================== 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 : @@ -32,28 +31,29 @@ mybox3d(BBox){} 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); } @@ -62,14 +62,14 @@ Project(const Handle(Select3D_Projector)& aProj) } //================================================== -// Function: +// Function: Areas // Purpose : //================================================== + void Select3D_SensitiveBox:: Areas(SelectBasics_ListOfBox2d& aSeq) { aSeq.Append(mybox2d);} - //======================================================================= //function : GetConnected //purpose : @@ -84,43 +84,39 @@ Handle(Select3D_SensitiveEntity) Select3D_SensitiveBox::GetConnected(const TopLo 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 : @@ -128,13 +124,12 @@ Matches (const Standard_Real XMin, 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 : @@ -152,10 +147,11 @@ void Select3D_SensitiveBox::Dump(Standard_OStream& S,const Standard_Boolean Full S<<"\t\t PMin [ "< #include -//======================================================================= -//function : Select3D_SensitiveCircle (constructeur) -//purpose : Definition of a sensitive circle -//======================================================================= + static Standard_Integer S3D_GetCircleNBPoints(const Handle(Geom_Circle)& C, const Standard_Integer anInputNumber) { @@ -26,6 +23,7 @@ static Standard_Integer S3D_GetCircleNBPoints(const Handle(Geom_Circle)& C, return 2*anInputNumber+1; return 1; } + static Standard_Integer S3D_GetArcNBPoints(const Handle(Geom_Circle)& C, const Standard_Integer anInputNumber) { @@ -33,19 +31,28 @@ static Standard_Integer S3D_GetArcNBPoints(const Handle(Geom_Circle)& C, 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(); @@ -76,40 +83,42 @@ myDetectedIndex(-1) // 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; + if(mynbpoints > 1) + { + gp_Pnt p1,p2; + gp_Vec v1; - Standard_Real ustart = u1; - Standard_Real uend = u2; + if (u1 > u2) + { + mystart = u2; + myend = u1; + } - if (u1 > u2) {ustart=u1;uend=u2;} - - 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++) { @@ -124,7 +133,7 @@ myDetectedIndex(-1) rank++; curu+=du; } - TheCircle->D0(uend,p1); + TheCircle->D0(myend,p1); ((Select3D_Pnt*)mypolyg3d)[NbPoints*2-2] = p1; // Get myCenter3D myCenter3D = TheCircle->Location(); @@ -141,12 +150,15 @@ myDetectedIndex(-1) //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(); @@ -154,12 +166,19 @@ myDetectedIndex(-1) 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(); @@ -167,13 +186,17 @@ myDetectedIndex(-1) 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; @@ -229,15 +252,19 @@ Matches(const Standard_Real X, 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; @@ -249,7 +276,6 @@ Matches(const Standard_Real XMin, return Standard_True; } - //======================================================================= //function : Matches //purpose : @@ -257,8 +283,8 @@ Matches(const Standard_Real XMin, 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); @@ -267,24 +293,31 @@ Matches (const TColgp_Array1OfPnt2d& aPoly, 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 @@ -317,9 +350,11 @@ void Select3D_SensitiveCircle::Dump(Standard_OStream& S,const Standard_Boolean F S<<"\t\tExisting Location"< 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); @@ -366,21 +456,26 @@ void Select3D_SensitiveCircle::Project(const Handle_Select3D_Projector &aProject 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]; } @@ -388,8 +483,8 @@ void Select3D_SensitiveCircle::ComputeCenter3D() // 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; } } diff --git a/src/Select3D/Select3D_SensitiveCurve.cdl b/src/Select3D/Select3D_SensitiveCurve.cdl index 9297f86855..484d8c65fa 100755 --- a/src/Select3D/Select3D_SensitiveCurve.cdl +++ b/src/Select3D/Select3D_SensitiveCurve.cdl @@ -24,7 +24,8 @@ uses Array1OfPnt2d from TColgp, HArray1OfPnt from TColgp, Box2d from Bnd, - Location from TopLoc + Location from TopLoc, + SensitiveEntity from Select3D is @@ -50,7 +51,7 @@ 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; @@ -85,9 +86,16 @@ is ---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; diff --git a/src/Select3D/Select3D_SensitiveCurve.cxx b/src/Select3D/Select3D_SensitiveCurve.cxx index b338ee628c..231dd25166 100755 --- a/src/Select3D/Select3D_SensitiveCurve.cxx +++ b/src/Select3D/Select3D_SensitiveCurve.cxx @@ -15,39 +15,44 @@ //================================================== -// 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) { } @@ -55,11 +60,12 @@ 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); @@ -73,11 +79,10 @@ Standard_Boolean Select3D_SensitiveCurve 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 @@ -86,11 +91,11 @@ Standard_Boolean Select3D_SensitiveCurve 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); @@ -108,9 +113,9 @@ Matches (const Standard_Real XMin, 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; @@ -118,17 +123,16 @@ Matches (const TColgp_Array1OfPnt2d& aPoly, Tolv = 1e-7; CSLib_Class2d aClassifier2d(aPoly,aTol,aTol,Umin,Vmin,Umax,Vmax); - for(Standard_Integer j=0;jSetValue(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 diff --git a/src/Select3D/Select3D_SensitiveEntity.cdl b/src/Select3D/Select3D_SensitiveEntity.cdl index 74238ff231..49953348a0 100755 --- a/src/Select3D/Select3D_SensitiveEntity.cdl +++ b/src/Select3D/Select3D_SensitiveEntity.cdl @@ -62,7 +62,12 @@ is 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. diff --git a/src/Select3D/Select3D_SensitiveEntity.cxx b/src/Select3D/Select3D_SensitiveEntity.cxx index 1303a5a8d3..4bf59882ee 100755 --- a/src/Select3D/Select3D_SensitiveEntity.cxx +++ b/src/Select3D/Select3D_SensitiveEntity.cxx @@ -39,9 +39,9 @@ void Select3D_SensitiveEntity::Project(const Handle(Select3D_Projector)& aPrj) //======================================================================= 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()) { @@ -62,10 +62,10 @@ Standard_Boolean Select3D_SensitiveEntity::Matches(const Standard_Real X, //======================================================================= 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; } @@ -76,8 +76,8 @@ Standard_Boolean Select3D_SensitiveEntity::Matches(const Standard_Real XMin, //======================================================================= 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; } @@ -99,13 +99,13 @@ void Select3D_SensitiveEntity::Dump(Standard_OStream& S,const Standard_Boolean F void Select3D_SensitiveEntity::DumpBox(Standard_OStream& S,const Bnd_Box2d& b2d) { - if(!b2d.IsVoid()){ + if(!b2d.IsVoid()) + { Standard_Real xmin,ymin,xmax,ymax; b2d.Get(xmin,ymin,xmax,ymax); S<<"\t\t\tBox2d: PMIN ["<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;I4) { -// 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); @@ -141,13 +133,14 @@ Matches(const Standard_Real X, 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) @@ -164,15 +157,16 @@ Matches(const Standard_Real X, 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; @@ -185,9 +179,9 @@ Matches (const Standard_Real XMin, 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; @@ -195,18 +189,19 @@ Matches (const TColgp_Array1OfPnt2d& aPoly, 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 :"<SetLocation(Location()); + + aNewEntity->UpdateLocation(theLocation); + + return aNewEntity; +} \ No newline at end of file diff --git a/src/Select3D/Select3D_SensitiveGroup.cdl b/src/Select3D/Select3D_SensitiveGroup.cdl index 1e576c4c6d..0af6bcfeec 100755 --- a/src/Select3D/Select3D_SensitiveGroup.cdl +++ b/src/Select3D/Select3D_SensitiveGroup.cdl @@ -130,7 +130,10 @@ is ---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; diff --git a/src/Select3D/Select3D_SensitiveGroup.cxx b/src/Select3D/Select3D_SensitiveGroup.cxx index 3cfcbf908c..8b4e7ee9b2 100755 --- a/src/Select3D/Select3D_SensitiveGroup.cxx +++ b/src/Select3D/Select3D_SensitiveGroup.cxx @@ -8,8 +8,12 @@ #include #include +//======================================================================= +//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), @@ -18,10 +22,14 @@ myY(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), @@ -35,6 +43,7 @@ myY(0.) //function : Add //purpose : No control of entities inside //======================================================================= + void Select3D_SensitiveGroup::Add(Select3D_ListOfSensitive& LL) {myList.Append(LL);} @@ -42,9 +51,11 @@ void Select3D_SensitiveGroup::Add(Select3D_ListOfSensitive& 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); @@ -54,10 +65,13 @@ void Select3D_SensitiveGroup::Add(const Handle(Select3D_SensitiveEntity)& aSensi //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; } @@ -68,19 +82,22 @@ void Select3D_SensitiveGroup::Remove(const Handle(Select3D_SensitiveEntity)& aSe //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();} @@ -93,7 +110,8 @@ void Select3D_SensitiveGroup::Project(const Handle(Select3D_Projector)& aProject { 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); } } @@ -105,7 +123,8 @@ void Select3D_SensitiveGroup::Project(const Handle(Select3D_Projector)& aProject 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); } } @@ -119,7 +138,8 @@ Handle(Select3D_SensitiveEntity) Select3D_SensitiveGroup::GetConnected(const Top { 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); @@ -135,18 +155,24 @@ void Select3D_SensitiveGroup::SetLocation(const TopLoc_Location& aLoc) { 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); - } } @@ -154,15 +180,16 @@ void Select3D_SensitiveGroup::SetLocation(const TopLoc_Location& 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(); } @@ -171,10 +198,11 @@ void Select3D_SensitiveGroup::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; @@ -198,25 +226,28 @@ Standard_Boolean Select3D_SensitiveGroup::Matches(const Standard_Real X, //purpose : si on doit tout matcher, on ne repond oui que si toutes // 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; @@ -229,27 +260,29 @@ Standard_Boolean Select3D_SensitiveGroup::Matches(const Standard_Real XMin, 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 @@ -285,6 +318,7 @@ Standard_Real Select3D_SensitiveGroup::ComputeDepth(const gp_Lin& EyeLine) const //function : MaxBoxes //purpose : //======================================================================= + Standard_Integer Select3D_SensitiveGroup::MaxBoxes() const { Standard_Integer nbboxes(0); @@ -294,9 +328,28 @@ Standard_Integer Select3D_SensitiveGroup::MaxBoxes() const 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); +} diff --git a/src/Select3D/Select3D_SensitivePoint.cxx b/src/Select3D/Select3D_SensitivePoint.cxx index 7c0115a072..69904688d1 100755 --- a/src/Select3D/Select3D_SensitivePoint.cxx +++ b/src/Select3D/Select3D_SensitivePoint.cxx @@ -14,13 +14,13 @@ #include //================================================== -// 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.); @@ -28,9 +28,10 @@ Select3D_SensitiveEntity(anOwner) } //================================================== -// Function: +// Function: Project // Purpose : //================================================== + void Select3D_SensitivePoint ::Project (const Handle(Select3D_Projector)& aProj) { @@ -38,7 +39,8 @@ void Select3D_SensitivePoint 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); } @@ -46,9 +48,10 @@ void Select3D_SensitivePoint } //================================================== -// Function: +// Function: Areas // Purpose : //================================================== + void Select3D_SensitivePoint ::Areas(SelectBasics_ListOfBox2d& boxes) { @@ -57,16 +60,16 @@ void Select3D_SensitivePoint 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()) @@ -77,12 +80,17 @@ Standard_Boolean Select3D_SensitivePoint 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)); @@ -90,7 +98,6 @@ Matches (const Standard_Real XMin, return !B.IsOut(myprojpt); } - //======================================================================= //function : Matches //purpose : @@ -98,8 +105,8 @@ Matches (const Standard_Real XMin, 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); @@ -114,12 +121,11 @@ Matches (const TColgp_Array1OfPnt2d& aPoly, return Standard_False; } - - //======================================================================= //function : Point //purpose : //======================================================================= + gp_Pnt Select3D_SensitivePoint::Point() const {return mypoint;} @@ -136,7 +142,6 @@ Handle(Select3D_SensitiveEntity) Select3D_SensitivePoint::GetConnected(const Top return NiouEnt; } - //======================================================================= //function : Dump //purpose : @@ -161,5 +166,3 @@ Standard_Real Select3D_SensitivePoint::ComputeDepth(const gp_Lin& EyeLine) const { return ElCLib::Parameter(EyeLine,mypoint); } - - diff --git a/src/Select3D/Select3D_SensitivePoly.cdl b/src/Select3D/Select3D_SensitivePoly.cdl index 99eea7842d..b086e9bf07 100755 --- a/src/Select3D/Select3D_SensitivePoly.cdl +++ b/src/Select3D/Select3D_SensitivePoly.cdl @@ -38,7 +38,7 @@ is ---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 @@ -69,4 +69,4 @@ fields mypolyg2d : Address from Standard is protected; mybox2d : Box2d from Select3D is protected; mynbpoints : Integer from Standard is protected; -end SensitiveFace; +end SensitivePoly; diff --git a/src/Select3D/Select3D_SensitivePoly.cxx b/src/Select3D/Select3D_SensitivePoly.cxx index 69b58d4906..b831e188ad 100755 --- a/src/Select3D/Select3D_SensitivePoly.cxx +++ b/src/Select3D/Select3D_SensitivePoly.cxx @@ -14,7 +14,7 @@ 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; @@ -25,13 +25,13 @@ Select3D_SensitiveEntity(OwnerId) } //================================================== -// 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; @@ -42,13 +42,13 @@ Select3D_SensitiveEntity(OwnerId) } //================================================== -// 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; @@ -57,7 +57,7 @@ Select3D_SensitiveEntity(OwnerId) } //================================================== -// Function: +// Function: Project // Purpose : //================================================== @@ -85,7 +85,7 @@ void Select3D_SensitivePoly::Project(const Handle(Select3D_Projector)& aProj) } //================================================== -// Function: +// Function: Areas // Purpose : //================================================== void Select3D_SensitivePoly @@ -95,7 +95,7 @@ void Select3D_SensitivePoly } //================================================== -// Function: +// Function: Destroy // Purpose : //================================================== void Select3D_SensitivePoly::Destroy() diff --git a/src/Select3D/Select3D_SensitiveSegment.cxx b/src/Select3D/Select3D_SensitiveSegment.cxx index d852b2a2c8..3879f59a9d 100755 --- a/src/Select3D/Select3D_SensitiveSegment.cxx +++ b/src/Select3D/Select3D_SensitiveSegment.cxx @@ -27,12 +27,11 @@ // 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) { @@ -44,6 +43,7 @@ mymaxrect(MaxRect) // Function : // Purpose : //===================================================== + void Select3D_SensitiveSegment ::Project(const Handle(Select3D_Projector)& aProj) { @@ -51,13 +51,15 @@ void Select3D_SensitiveSegment 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); } @@ -69,43 +71,48 @@ void Select3D_SensitiveSegment // 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); } } } @@ -114,11 +121,12 @@ void Select3D_SensitiveSegment // 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); @@ -127,12 +135,17 @@ Standard_Boolean Select3D_SensitiveSegment 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); @@ -141,7 +154,6 @@ Matches (const Standard_Real XMin, return Standard_True; } - //======================================================================= //function : Matches //purpose : @@ -149,8 +161,8 @@ Matches (const Standard_Real XMin, 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); @@ -173,9 +185,13 @@ Matches (const TColgp_Array1OfPnt2d& aPoly, //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; diff --git a/src/Select3D/Select3D_SensitiveTriangle.cdl b/src/Select3D/Select3D_SensitiveTriangle.cdl index 5b69cec092..2cb6a836ea 100755 --- a/src/Select3D/Select3D_SensitiveTriangle.cdl +++ b/src/Select3D/Select3D_SensitiveTriangle.cdl @@ -21,7 +21,8 @@ uses XY from gp, Pnt from gp, TypeOfSensitivity from Select3D, - Location from TopLoc + Location from TopLoc, + SensitiveEntity from Select3D is Create (OwnerId : EntityOwner from SelectBasics; @@ -30,7 +31,7 @@ is 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; @@ -85,7 +86,13 @@ is 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 diff --git a/src/Select3D/Select3D_SensitiveTriangle.cxx b/src/Select3D/Select3D_SensitiveTriangle.cxx index 6a3f296a67..f5c7e51a9e 100755 --- a/src/Select3D/Select3D_SensitiveTriangle.cxx +++ b/src/Select3D/Select3D_SensitiveTriangle.cxx @@ -43,16 +43,16 @@ static Standard_Boolean S3D_Str_NearSegment (const gp_XY& p0, const gp_XY& p1, c } //================================================== -// 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) { @@ -62,21 +62,22 @@ 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; @@ -92,25 +93,31 @@ Matches(const Standard_Real X, 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 : @@ -118,8 +125,8 @@ Matches (const Standard_Real XMin, 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); @@ -128,20 +135,31 @@ Matches (const TColgp_Array1OfPnt2d& aPoly, 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]); @@ -149,7 +167,12 @@ gp_Pnt Select3D_SensitiveTriangle::Center3D() const CDG += ((Select3D_Pnt*)mypolyg3d)[2]; CDG /=3.; return gp_Pnt(CDG);; -} +} + +//================================================== +// Function: Center2D +// Purpose : +//================================================== gp_XY Select3D_SensitiveTriangle::Center2D() const { @@ -163,30 +186,26 @@ gp_XY Select3D_SensitiveTriangle::Center2D() const //======================================================================= Standard_Integer Select3D_SensitiveTriangle::Status(const Standard_Real X, - 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); @@ -277,7 +296,7 @@ Standard_Integer Select3D_SensitiveTriangle::Status(const gp_XY& p0, DMin = ( aD < 0 ? -aD : 0. ); return 0; } - + //======================================================================= //function : Dump //purpose : @@ -295,7 +314,8 @@ void Select3D_SensitiveTriangle::Dump(Standard_OStream& S,const Standard_Boolean S<<"\t\t P1 [ "<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 diff --git a/src/Select3D/Select3D_SensitiveTriangulation.cxx b/src/Select3D/Select3D_SensitiveTriangulation.cxx index d87052ada0..3be96f093f 100755 --- a/src/Select3D/Select3D_SensitiveTriangulation.cxx +++ b/src/Select3D/Select3D_SensitiveTriangulation.cxx @@ -78,10 +78,10 @@ static Standard_Boolean S3D_STriangul_NearSegment (const gp_XY& p0, const gp_XY& // } static Standard_Boolean S3D_IsEdgeIn(const Standard_Integer e1, - 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; @@ -91,19 +91,17 @@ static Standard_Boolean S3D_IsEdgeIn(const Standard_Integer e1, 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), @@ -121,34 +119,38 @@ myDetectedTr(-1) 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); @@ -163,13 +165,14 @@ myDetectedTr(-1) //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), @@ -180,6 +183,7 @@ myNodes2d(1,Trg->NbNodes()), myDetectedTr(-1) { } + //======================================================================= //function : Project //purpose : @@ -221,10 +225,11 @@ void Select3D_SensitiveTriangulation::Areas(SelectBasics_ListOfBox2d& boxes) //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()) @@ -319,26 +324,27 @@ Standard_Boolean Select3D_SensitiveTriangulation::Matches(const Standard_Real X, //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 : @@ -346,8 +352,8 @@ Standard_Boolean Select3D_SensitiveTriangulation::Matches(const Standard_Real XM 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); @@ -356,21 +362,26 @@ Matches (const TColgp_Array1OfPnt2d& aPoly, 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); } @@ -381,24 +392,31 @@ Standard_Integer Select3D_SensitiveTriangulation::Status (const gp_XY& TheP, //======================================================================= 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(); + TColStd_Array1OfInteger& FreeE = myFreeEdges->ChangeArray1(); - 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;} + 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; @@ -409,32 +427,38 @@ Standard_Boolean Select3D_SensitiveTriangulation::IsFree(const Standard_Integer //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); @@ -460,7 +484,8 @@ void Select3D_SensitiveTriangulation::Dump(Standard_OStream& S,const Standard_Bo S<<"\t\tNb Nodes : "<NbNodes()<Length()/2< 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])); @@ -554,9 +585,11 @@ Standard_Real Select3D_SensitiveTriangulation::ComputeDepth(const gp_Lin& EyeLin //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(); @@ -567,7 +600,8 @@ Standard_Boolean Select3D_SensitiveTriangulation::DetectedTriangle(gp_Pnt& P1, 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); @@ -580,8 +614,11 @@ Standard_Boolean Select3D_SensitiveTriangulation::DetectedTriangle(gp_Pnt& P1, // 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... @@ -603,23 +640,30 @@ Standard_Boolean Select3D_SensitiveTriangulation::DetectedTriangle2d( } 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; } diff --git a/src/Select3D/Select3D_SensitiveWire.cdl b/src/Select3D/Select3D_SensitiveWire.cdl index b767491c09..e6ed1693e1 100755 --- a/src/Select3D/Select3D_SensitiveWire.cdl +++ b/src/Select3D/Select3D_SensitiveWire.cdl @@ -95,7 +95,10 @@ is ---Purpose:returns - 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; diff --git a/src/Select3D/Select3D_SensitiveWire.cxx b/src/Select3D/Select3D_SensitiveWire.cxx index 6cd72117a4..8e8b2bf066 100755 --- a/src/Select3D/Select3D_SensitiveWire.cxx +++ b/src/Select3D/Select3D_SensitiveWire.cxx @@ -22,10 +22,9 @@ // 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) @@ -35,16 +34,12 @@ 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); } //======================================================================= @@ -64,14 +59,15 @@ void Select3D_SensitiveWire::SetLocation(const TopLoc_Location& aLoc) 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 : @@ -89,6 +85,7 @@ void Select3D_SensitiveWire::ResetLocation() } Select3D_SensitiveEntity::ResetLocation(); } + //===================================================== // Function : Project // Purpose : @@ -96,7 +93,7 @@ void Select3D_SensitiveWire::ResetLocation() 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); } @@ -105,6 +102,7 @@ void Select3D_SensitiveWire // Function : Areas // Purpose : //===================================================== + void Select3D_SensitiveWire ::Areas(SelectBasics_ListOfBox2d& theareas) { @@ -118,7 +116,6 @@ void Select3D_SensitiveWire BB.Add(it.Value()); theareas.Append(BB); - } //===================================================== @@ -127,20 +124,23 @@ void Select3D_SensitiveWire //===================================================== 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; } } } @@ -155,15 +155,17 @@ Standard_Boolean Select3D_SensitiveWire // 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; } @@ -177,11 +179,12 @@ Matches (const Standard_Real XMin, 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; } @@ -193,6 +196,7 @@ Matches (const TColgp_Array1OfPnt2d& aPoly, // Function : MaxBoxes // Purpose : //===================================================== + Standard_Integer Select3D_SensitiveWire:: MaxBoxes () const { @@ -203,11 +207,12 @@ 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); @@ -241,6 +246,7 @@ void Select3D_SensitiveWire::Dump(Standard_OStream& S,const Standard_Boolean Ful //function : ComputeDepth //purpose : //======================================================================= + Standard_Real Select3D_SensitiveWire::ComputeDepth(const gp_Lin& EyeLine) const { @@ -255,6 +261,7 @@ Standard_Real Select3D_SensitiveWire::ComputeDepth(const gp_Lin& EyeLine) const //function : SetLastPrj //purpose : //======================================================================= + void Select3D_SensitiveWire::SetLastPrj(const Handle(Select3D_Projector)& Prj) { Select3D_SensitiveEntity::SetLastPrj(Prj); @@ -267,6 +274,7 @@ void Select3D_SensitiveWire::SetLastPrj(const Handle(Select3D_Projector)& Prj) //function : GetEdges //purpose : returns the sensitive edges stored in this wire //======================================================================= + void Select3D_SensitiveWire::GetEdges( Select3D_SensitiveEntitySequence& theEdges ) { theEdges.Clear(); @@ -277,6 +285,7 @@ void Select3D_SensitiveWire::GetEdges( Select3D_SensitiveEntitySequence& theEdge // Function : GetLastDetected // Purpose : //============================================================================= + Handle(Select3D_SensitiveEntity) Select3D_SensitiveWire::GetLastDetected() const { Handle(Select3D_SensitiveEntity) aRes; @@ -286,3 +295,19 @@ Handle(Select3D_SensitiveEntity) Select3D_SensitiveWire::GetLastDetected() const 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); + } +} diff --git a/src/SelectBasics/SelectBasics_SensitiveEntity.cdl b/src/SelectBasics/SelectBasics_SensitiveEntity.cdl index 126688b6db..25fac30b0b 100755 --- a/src/SelectBasics/SelectBasics_SensitiveEntity.cdl +++ b/src/SelectBasics/SelectBasics_SensitiveEntity.cdl @@ -23,7 +23,7 @@ is aSensitivityFactor : ShortReal from Standard =1); - Set (me:mutable ; TheOwnerId : EntityOwner) is static; + Set (me:mutable ; TheOwnerId : EntityOwner) is virtual; ---Level: Public diff --git a/src/ViewerTest/ViewerTest_ObjectCommands.cxx b/src/ViewerTest/ViewerTest_ObjectCommands.cxx index 48a879c775..589abbb3f4 100755 --- a/src/ViewerTest/ViewerTest_ObjectCommands.cxx +++ b/src/ViewerTest/ViewerTest_ObjectCommands.cxx @@ -109,7 +109,12 @@ #include #include #include -#include +#include + +#include +#include +#include +#include #ifdef HAVE_STRINGS_H #include @@ -3485,6 +3490,327 @@ static Standard_Integer VSetLocation (Draw_Interpretor& di, 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 : @@ -3569,4 +3895,16 @@ void ViewerTest::ObjectCommands(Draw_Interpretor& theCommands) 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); }