static Standard_Integer S3D_GetCircleNBPoints(const Handle(Geom_Circle)& C,
const Standard_Integer anInputNumber)
-{
- if(C->Radius()>Precision::Confusion())
+{
+ // Check if number of points is invalid.
+ // In this case mypolyg raises Standard_ConstructionError
+ // exception (look constructor bellow).
+ if (anInputNumber <= 0)
+ return 0;
+
+ if (C->Radius()>Precision::Confusion())
return 2*anInputNumber+1;
+ // The radius is too small and circle degenerates into point
return 1;
}
static Standard_Integer S3D_GetArcNBPoints(const Handle(Geom_Circle)& C,
const Standard_Integer anInputNumber)
-{
- if(C->Radius()>Precision::Confusion())
+{
+ // There is no need to check number of points here.
+ // In case of invalid number of points this method returns
+ // -1 or smaller value.
+ if (C->Radius()>Precision::Confusion())
return 2*anInputNumber-1;
+
+ // The radius is too small and circle degenerates into point
return 1;
}
const Standard_Integer NbPoints):
Select3D_SensitivePoly(OwnerId, S3D_GetCircleNBPoints(TheCircle,NbPoints)),
myFillStatus(FilledCircle),
-myDetectedIndex(-1),
-myCircle(TheCircle),
-mystart(0),
+myDetectedIndex(-1),
+myCircle(TheCircle),
+mystart(0),
myend(0)
{
- if(mynbpoints!=1)
+ if (mypolyg.Size() != 1)
{
gp_Pnt p1,p2;
gp_Vec v1;
Standard_Real R = TheCircle->Radius();
Standard_Integer rank = 1;
Standard_Real curu =ustart;
- for(Standard_Integer i=1;i<=NbPoints;i++)
+ for(Standard_Integer anIndex=1;anIndex<=NbPoints;anIndex++)
{
TheCircle->D1(curu,p1,v1);
v1.Normalize();
- ((Select3D_Pnt*)mypolyg3d)[rank-1] = p1;
+ mypolyg.SetPnt(rank-1, p1);
rank++;
p2 = gp_Pnt(p1.X()+v1.X()*tan(du/2.)*R,
p1.Y()+v1.Y()*tan(du/2.)*R,
p1.Z()+v1.Z()*tan(du/2.)*R);
- ((Select3D_Pnt*)mypolyg3d)[rank-1] = p2;
+ mypolyg.SetPnt(rank-1, p2);
rank++;
curu+=du;
}
- ((Select3D_Pnt*)mypolyg3d)[NbPoints*2] = ((Select3D_Pnt*)mypolyg3d)[0];
- // Get myCenter3D
+
+ // Copy the first point to the last point of mypolyg
+ mypolyg.SetPnt(NbPoints*2, mypolyg.Pnt(0));
+ // Get myCenter3D
myCenter3D = TheCircle->Location();
}
// Radius = 0.0
else
{
- ((Select3D_Pnt*)mypolyg3d)[0] = TheCircle->Location();
+ mypolyg.SetPnt(0, TheCircle->Location());
// Get myCenter3D
- myCenter3D = ((Select3D_Pnt*)mypolyg3d)[0];
+ myCenter3D = mypolyg.Pnt(0);
}
}
const Standard_Integer NbPoints):
Select3D_SensitivePoly(OwnerId, S3D_GetArcNBPoints(TheCircle,NbPoints)),
myFillStatus(FilledCircle),
-myDetectedIndex(-1),
-myCircle(TheCircle),
-mystart(u1),
+myDetectedIndex(-1),
+myCircle(TheCircle),
+mystart(u1),
myend(u2)
{
- if(mynbpoints > 1)
+ if (mypolyg.Size() != 1)
{
gp_Pnt p1,p2;
gp_Vec v1;
- if (u1 > u2)
+ if (u1 > u2)
{
- mystart = u2;
+ mystart = u2;
myend = u1;
}
Standard_Real du = (myend-mystart)/(NbPoints-1);
Standard_Real R = TheCircle->Radius();
Standard_Integer rank = 1;
- Standard_Real curu = mystart;
+ Standard_Real curu = mystart;
- for(Standard_Integer i=1;i<=NbPoints-1;i++)
+ for(Standard_Integer anIndex=1;anIndex<=NbPoints-1;anIndex++)
{
TheCircle->D1(curu,p1,v1);
v1.Normalize();
- ((Select3D_Pnt*)mypolyg3d)[rank-1] = p1;
+ mypolyg.SetPnt(rank-1, p1);
rank++;
p2 = gp_Pnt(p1.X()+v1.X()*tan(du/2.)*R,
p1.Y()+v1.Y()*tan(du/2.)*R,
p1.Z()+v1.Z()*tan(du/2.)*R);
- ((Select3D_Pnt*)mypolyg3d)[rank-1] = p2;
+ mypolyg.SetPnt(rank-1, p2);
rank++;
curu+=du;
}
TheCircle->D0(myend,p1);
- ((Select3D_Pnt*)mypolyg3d)[NbPoints*2-2] = p1;
+ mypolyg.SetPnt(NbPoints*2-2, p1);
// Get myCenter3D
myCenter3D = TheCircle->Location();
}
else
{
- ((Select3D_Pnt*)mypolyg3d)[0] = TheCircle->Location();
+ mypolyg.SetPnt(0, TheCircle->Location());
// Get myCenter3D
- myCenter3D = ((Select3D_Pnt*)mypolyg3d)[0];
+ myCenter3D = mypolyg.Pnt(0);
}
}
const Standard_Boolean FilledCircle):
Select3D_SensitivePoly(OwnerId, Thepolyg3d),
myFillStatus(FilledCircle),
-myDetectedIndex(-1),
-mystart(0),
+myDetectedIndex(-1),
+mystart(0),
myend(0)
{
- if (mynbpoints > 1)
+ if (mypolyg.Size() != 1)
ComputeCenter3D();
- else
- myCenter3D = ((Select3D_Pnt*)mypolyg3d)[0];
+ else
+ myCenter3D = mypolyg.Pnt(0);
}
//=======================================================================
const Standard_Boolean FilledCircle):
Select3D_SensitivePoly(OwnerId, Thepolyg3d),
myFillStatus(FilledCircle),
-myDetectedIndex(-1),
-mystart(0),
+myDetectedIndex(-1),
+mystart(0),
myend(0)
-{
- if (mynbpoints > 1)
+{
+ if (mypolyg.Size() != 1)
ComputeCenter3D();
- else
- myCenter3D = ((Select3D_Pnt*)mypolyg3d)[0];
+ else
+ myCenter3D = mypolyg.Pnt(0);
}
//=======================================================================
//=======================================================================
Standard_Boolean Select3D_SensitiveCircle::
-Matches(const Standard_Real X,
- const Standard_Real Y,
- const Standard_Real aTol,
+Matches(const Standard_Real X,
+ const Standard_Real Y,
+ const Standard_Real aTol,
Standard_Real& DMin)
{
- if(mynbpoints>1)
+ Standard_Integer aSize = mypolyg.Size();
+ if (aSize != 1)
{
Standard_Boolean Found = Standard_False;
- Standard_Integer i = 0;
+ Standard_Integer anIndex = 0;
if(!myFillStatus)
{
- while(i < mynbpoints-2 && !Found)
- {
- Standard_Integer TheStat =
- Select3D_SensitiveTriangle::Status(((Select3D_Pnt2d*)mypolyg2d)[i],
- ((Select3D_Pnt2d*)mypolyg2d)[i+1],
- ((Select3D_Pnt2d*)mypolyg2d)[i+2],
- gp_XY(X,Y),aTol,DMin);
- Found = (TheStat != 2);
- if(Found) myDetectedIndex = i;
- i += 2;
+ while(anIndex < aSize-2 && !Found)
+ {
+ Standard_Integer TheStat =
+ Select3D_SensitiveTriangle::Status(mypolyg.Pnt2d(anIndex),
+ mypolyg.Pnt2d(anIndex+1),
+ mypolyg.Pnt2d(anIndex+2),
+ gp_XY(X,Y),aTol,DMin);
+ Found = (TheStat != 2);
+ if(Found) myDetectedIndex = anIndex;
+ anIndex += 2;
}
}
- else
+ else
{
myDetectedIndex =-1;
Standard_Real Xmin,Ymin,Xmax,Ymax;
// Get coordinates of the bounding box
- Bnd_Box2d(mybox2d).Get(Xmin,Ymin,Xmax,Ymax);
- TColgp_Array1OfPnt2d anArrayOf2dPnt(1, mynbpoints);
-
+ Bnd_Box2d(mybox2d).Get(Xmin,Ymin,Xmax,Ymax);
+ TColgp_Array1OfPnt2d anArrayOf2dPnt(1, aSize);
+
// Fill anArrayOf2dPnt with points from mypolig2d
- Points2D(anArrayOf2dPnt);
+ Points2D(anArrayOf2dPnt);
CSLib_Class2d anInOutTool(anArrayOf2dPnt,aTol,aTol,Xmin,Ymin,Xmax,Ymax);
// 0 - the point is on the circle
// -1 - the point is outside the circle
Standard_Integer aStat = anInOutTool.SiDans(gp_Pnt2d(X,Y));
- if(aStat != -1)
+ if(aStat != -1)
{
// Compute DMin (a distance between the center and the point)
DMin = gp_XY(myCenter2D.x - X, myCenter2D.y - Y).Modulus();
Select3D_SensitiveEntity::Matches(X,Y,aTol,DMin);
return Standard_True;
}
- return Standard_False;
+ return Standard_False;
}
- if(!Found)
+ if(!Found)
myDetectedIndex=-1;
else
Select3D_SensitiveEntity::Matches(X,Y,aTol,DMin);
-
return Found;
}
- return Standard_True;
+ // Circle degenerates into point
+ DMin = gp_Pnt2d(X, Y).Distance(mypolyg.Pnt2d(0));
+ if (DMin <= aTol*SensitivityFactor())
+ return Select3D_SensitiveEntity::Matches(X,Y,aTol,DMin);
+
+ return Standard_False;
}
//=======================================================================
Bnd_Box2d abox;
abox.Update(Min(XMin,XMax),Min(YMin,YMax),Max(XMin,XMax),Max(YMin,YMax));
abox.Enlarge(aTol);
- for(Standard_Integer i=0;i<mynbpoints;i++)
- if(abox.IsOut(((Select3D_Pnt2d*)mypolyg2d)[i])) return Standard_False;
+ for(Standard_Integer anIndex=0;anIndex<mypolyg.Size();anIndex++)
+ {
+ if(abox.IsOut(mypolyg.Pnt2d(anIndex)))
+ return Standard_False;
+ }
return Standard_True;
}
Matches (const TColgp_Array1OfPnt2d& aPoly,
const Bnd_Box2d& aBox,
const Standard_Real aTol)
-{
+{
+ myDetectedIndex = -1;
Standard_Real Umin,Vmin,Umax,Vmax;
aBox.Get(Umin,Vmin,Umax,Vmax);
Standard_Real Tolu,Tolv;
- Tolu = 1e-7;
- Tolv = 1e-7;
+ Tolu = Precision::Confusion();
+ Tolv = Precision::Confusion();
CSLib_Class2d aClassifier2d(aPoly,aTol,aTol,Umin,Vmin,Umax,Vmax);
- for(Standard_Integer j=1;j<=mynbpoints;j++)
+ for(Standard_Integer anIndex=0;anIndex<mypolyg.Size();++anIndex)
{
- Standard_Integer RES = aClassifier2d.SiDans(((Select3D_Pnt2d*)mypolyg2d)[j-1]);
- if(RES!=1) return Standard_False;
+ Standard_Integer RES = aClassifier2d.SiDans(mypolyg.Pnt2d(anIndex));
+ if(RES!=1)
+ return Standard_False;
}
return Standard_True;
}
ArrayBounds(Standard_Integer & Low,
Standard_Integer & Up) const
{
- Low = 0;
- Up = mynbpoints-1;
+ Low = 0;
+ Up = mypolyg.Size()-1;
}
//=======================================================================
gp_Pnt Select3D_SensitiveCircle::
GetPoint3d(const Standard_Integer Rank) const
{
- if(Rank>=0&& Rank<mynbpoints)
- return ((Select3D_Pnt*)mypolyg3d)[Rank];
- return ((Select3D_Pnt*)mypolyg3d)[0];
+ if(Rank>=0 && Rank<mypolyg.Size())
+ return mypolyg.Pnt(Rank);
+ return gp_Pnt();
}
void Select3D_SensitiveCircle::Dump(Standard_OStream& S,const Standard_Boolean FullDump) const
{
- // Standard_Integer rank(1);
- gp_XYZ CDG(0.,0.,0.);
+ Standard_Integer aSize = mypolyg.Size();
S<<"\tSensitiveCircle 3D :";
- Standard_Boolean isclosed = 1== mynbpoints;
+ Standard_Boolean isclosed = 1== aSize;
if(isclosed)
S<<"(Closed Circle)"<<endl;
else
if(FullDump)
{
- Standard_Integer EndIndex = isclosed? mynbpoints-2 : mynbpoints-1, nbpt(0);
- for(Standard_Integer i=0;i<EndIndex;i+=2)
- {
- CDG +=((Select3D_Pnt*)mypolyg3d)[i];
- nbpt++;
- }
-
- CDG/=nbpt;
-
- Standard_Real R = (CDG-((Select3D_Pnt*)mypolyg3d)[0]).Modulus();
-
- S<<"\t\t Center : ("<<CDG.X()<<" , "<<CDG.Y()<<" , "<<CDG.Z()<<" )"<<endl;
+ gp_XYZ aCenter = myCenter3D;
+ Standard_Real R = (aCenter-mypolyg.Pnt(0)).Modulus();
+
+ S<<"\t\t Center : ("<<aCenter.X()<<" , "<<aCenter.Y()<<" , "<<aCenter.Z()<<" )"<<endl;
S<<"\t\t Radius :"<<R<<endl;
-
}
}
Standard_Real Select3D_SensitiveCircle::ComputeDepth(const gp_Lin& EyeLine) const
{
- gp_Pnt CDG;
+ gp_XYZ aCDG;
if(myDetectedIndex==-1)
{
- gp_XYZ CurCoord(((Select3D_Pnt*)mypolyg3d)[0]);
- Standard_Boolean isclosed = 1==mynbpoints;
- Standard_Integer EndIndex = isclosed ? mynbpoints-2 : mynbpoints-1, nbpt(0);
- for(Standard_Integer i=1;i<EndIndex;i+=2)
- {
- CurCoord +=((Select3D_Pnt*)mypolyg3d)[i];
- nbpt++;
- }
- CDG.SetXYZ(CurCoord);
+ aCDG = myCenter3D;
}
else
{
- gp_XYZ CurCoord(((Select3D_Pnt*)mypolyg3d)[myDetectedIndex]);
- CurCoord+=((Select3D_Pnt*)mypolyg3d)[myDetectedIndex+1];
- CurCoord+=((Select3D_Pnt*)mypolyg3d)[myDetectedIndex+2];
- CDG.SetXYZ(CurCoord);
+ aCDG += mypolyg.Pnt(myDetectedIndex);
+ aCDG += mypolyg.Pnt(myDetectedIndex+1);
+ aCDG += mypolyg.Pnt(myDetectedIndex+2);
+ aCDG /= 3.;
}
-
- return ElCLib::Parameter(EyeLine,CDG);
+ return ElCLib::Parameter(EyeLine,gp_Pnt(aCDG));
}
//=======================================================================
//function : GetConnected
//purpose :
-//=======================================================================
+//=======================================================================
Handle(Select3D_SensitiveEntity) Select3D_SensitiveCircle::GetConnected(const TopLoc_Location& theLocation)
{
// this was constructed using TColgp_Array1OfPnt
else
{
- TColgp_Array1OfPnt aPolyg(1, mynbpoints);
- for(Standard_Integer i = 1; i <= mynbpoints; ++i)
+ Standard_Integer aSize = mypolyg.Size();
+ TColgp_Array1OfPnt aPolyg(1, aSize);
+ for(Standard_Integer anIndex = 1; anIndex <= aSize; ++anIndex)
{
- aPolyg.SetValue(i, ((Select3D_Pnt*)mypolyg3d)[i-1]);
+ aPolyg.SetValue(anIndex, mypolyg.Pnt(anIndex-1));
}
aNewEntity = new Select3D_SensitiveCircle(myOwnerId, aPolyg, myFillStatus);
}
//purpose :
//=======================================================================
-void Select3D_SensitiveCircle::Project(const Handle_Select3D_Projector &aProjector)
+void Select3D_SensitiveCircle::Project(const Handle_Select3D_Projector &aProjector)
{
Select3D_SensitivePoly::Project(aProjector);
- // Project the center of the circle
gp_Pnt2d aCenter;
aProjector->Project(myCenter3D, aCenter);
myCenter2D = aCenter;
//purpose :
//=======================================================================
-void Select3D_SensitiveCircle::ComputeCenter3D()
+void Select3D_SensitiveCircle::ComputeCenter3D()
{
- gp_XYZ aCenter(0., 0., 0.);
- if(mynbpoints > 1)
+ gp_XYZ aCenter;
+ Standard_Integer nbpoints = mypolyg.Size();
+ if (nbpoints != 1)
{
// The mass of points system
- Standard_Integer aMass = mynbpoints - 1;
+ Standard_Integer aMass = nbpoints - 1;
// Find the circle barycenter
- for(Standard_Integer i = 0; i < mynbpoints-1; ++i)
+ for (Standard_Integer anIndex = 0; anIndex < nbpoints-1; ++anIndex)
{
- aCenter += ((Select3D_Pnt*)mypolyg3d)[i];
+ aCenter += mypolyg.Pnt(anIndex);
}
myCenter3D = aCenter / aMass;
}
- else if (mynbpoints == 1)
- {
- myCenter3D = ((Select3D_Pnt*)mypolyg3d)[0];
- }
- // bad case! there are no points in mypolyg3d
- // It can lead to incorrect computation of
- // parameter DMin in method Matches.
- // In spite of this myCenter3D isn't left uninitialized
else
{
- myCenter3D = aCenter;
+ myCenter3D = mypolyg.Pnt(0);
}
}
#include <TColStd_ListOfInteger.hxx>
#include <TColStd_ListIteratorOfListOfInteger.hxx>
+#include <Select3D_SensitiveTriangle.hxx>
+#include <Select3D_SensitiveCurve.hxx>
+#include <BRepAdaptor_Curve.hxx>
+#include <StdPrs_Curve.hxx>
+
+#include <BRepExtrema_ExtPC.hxx>
+#include <BRepExtrema_ExtPF.hxx>
+
#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif
}
//==============================================================================
-// Fonction 1st click 2de click 3de click
+// Function 1st click 2de click 3de click
// vplane Vertex Vertex Vertex
// Vertex Edge
// Edge Vertex
//==============================================================================
//function : VPlaneBuilder
-//purpose : Build an AIS_Plane from selected entities or Named AIs components
+//purpose : Build an AIS_Plane from selected entities or Named AIS components
//Draw arg : vplane PlaneName [AxisName] [PointName]
// [PointName] [PointName] [PointName]
// [PlaneName] [PointName]
//==============================================================================
-#include <TopoDS_Edge.hxx>
-#include <TopoDS_Vertex.hxx>
-#include <TopoDS_Face.hxx>
-#include <TopExp.hxx>
-#include <AIS_Plane.hxx>
-#include <Geom_CartesianPoint.hxx>
-#include <Geom_Plane.hxx>
-#include <BRepExtrema_ExtPC.hxx>
-#include <BRepExtrema_ExtPF.hxx>
-#include <BRepAdaptor_Surface.hxx>
-#include <gp_Pln.hxx>
-#include <GC_MakePlane.hxx>
-
-static int VPlaneBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
+static Standard_Integer VPlaneBuilder (Draw_Interpretor& di,
+ Standard_Integer argc,
+ const char** argv)
{
// Declarations
- Standard_Boolean HasArg;
- TCollection_AsciiString name;
- Standard_Integer myCurrentIndex;
+ Standard_Boolean hasArg;
+ TCollection_AsciiString aName;
+ Standard_Integer aCurrentIndex;
// Verification
- if (argc<2 || argc>5 ) {di<<" Syntaxe error"<<"\n";return 1;}
- if (argc==5 || argc==4) HasArg=Standard_True;
- else HasArg=Standard_False;
+ if (argc<2 || argc>5 )
+ {
+ std::cout<<" Syntax error\n";
+ return 1;
+ }
+ if (argc==5 || argc==4)
+ hasArg=Standard_True;
+ else
+ hasArg=Standard_False;
- name=argv[1];
- // Fermeture des contextes
+ aName=argv[1];
+ // Close all contexts
TheAISContext()->CloseAllContexts();
-
- // Il y a des arguments
- if (HasArg) {
- if (!GetMapOfAIS().IsBound2(argv[2] ) ) {di<<"vplane: error 1st name doesn't exist in the GetMapOfAIS()."<<"\n";return 1;}
- // on recupere la shape dans la map
- Handle(AIS_InteractiveObject) theShapeA =
+ // There are some arguments
+ if (hasArg)
+ {
+ if (!GetMapOfAIS().IsBound2(argv[2] ))
+ {
+ std::cout<<"vplane: error 1st name doesn't exist in the GetMapOfAIS()\n";
+ return 1;
+ }
+ // Get shape from map
+ Handle(AIS_InteractiveObject) aShapeA =
Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[2] ));
- // Le premier argument est un AIS_Point 1
- if (!theShapeA.IsNull() &&
- theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1) {
- // le deuxieme argument doit etre un AIS_Point aussi
- if (argc<5 || !GetMapOfAIS().IsBound2(argv[3] ) ) {di<<"vplane: error 2de name doesn't exist in the GetMapOfAIS()."<<"\n";return 1;}
- // on recupere la shape dans la map
- Handle(AIS_InteractiveObject) theShapeB =
+ // The first argument is an AIS_Point
+ if (!aShapeA.IsNull() &&
+ aShapeA->Type()==AIS_KOI_Datum &&
+ aShapeA->Signature()==1)
+ {
+ // The second argument must also be an AIS_Point
+ if (argc<5 || !GetMapOfAIS().IsBound2(argv[3]))
+ {
+ std::cout<<"vplane: error 2nd name doesn't exist in the GetMapOfAIS()\n";
+ return 1;
+ }
+ // Get shape from map
+ Handle(AIS_InteractiveObject) aShapeB =
Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
- // si B n'est pas un AIS_Point
- if (theShapeB.IsNull() ||
- (!(theShapeB->Type()==AIS_KOI_Datum && theShapeB->Signature()==1)))
+ // If B is not an AIS_Point
+ if (aShapeB.IsNull() ||
+ (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
{
- di<<"vplane: error 2de object is expected to be an AIS_Point. "<<"\n";
+ std::cout<<"vplane: error 2nd object is expected to be an AIS_Point.\n";
return 1;
}
- // le troisieme objet est un AIS_Point
- if (!GetMapOfAIS().IsBound2(argv[4]) ) {di<<"vplane: error 3de name doesn't exist in the GetMapOfAIS()."<<"\n";return 1; }
- // on recupere la shape dans la map
- Handle(AIS_InteractiveObject) theShapeC =
+ // The third object is an AIS_Point
+ if (!GetMapOfAIS().IsBound2(argv[4]) )
+ {
+ std::cout<<"vplane: error 3d name doesn't exist in the GetMapOfAIS().\n";
+ return 1;
+ }
+ // Get shape from map
+ Handle(AIS_InteractiveObject) aShapeC =
Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[4]));
- // si C n'est pas un AIS_Point
- if (theShapeC.IsNull() ||
- (!(theShapeC->Type()==AIS_KOI_Datum && theShapeC->Signature()==1)))
+ // If C is not an AIS_Point
+ if (aShapeC.IsNull() ||
+ (!(aShapeC->Type()==AIS_KOI_Datum && aShapeC->Signature()==1)))
{
- di<<"vplane: error 3de object is expected to be an AIS_Point. "<<"\n";
+ std::cout<<"vplane: error 3d object is expected to be an AIS_Point.\n";
return 1;
}
- // Traitement des objets A,B,C
- // Downcaste de AIS_IO en AIS_Point
- Handle(AIS_Point) theAISPointA= *(Handle(AIS_Point)*)& theShapeA;
- Handle(AIS_Point) theAISPointB= *(Handle(AIS_Point)*)& theShapeB;
- Handle(AIS_Point) theAISPointC= *(Handle(AIS_Point)*)& theShapeC;
+ // Treatment of objects A, B, C
+ // Downcast an AIS_IO to AIS_Point
+ Handle(AIS_Point) anAISPointA = Handle(AIS_Point)::DownCast( aShapeA);
+ Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast( aShapeB);
+ Handle(AIS_Point) anAISPointC = Handle(AIS_Point)::DownCast( aShapeC);
- Handle(Geom_Point ) myGeomPointA= theAISPointA->Component();
- Handle(Geom_CartesianPoint ) myCartPointA= *((Handle(Geom_CartesianPoint)*)& myGeomPointA);
- // Handle(Geom_CartesianPoint ) myCartPointA= *(Handle(Geom_CartesianPoint)*)& (theAISPointA->Component() ) ;
+ Handle(Geom_CartesianPoint ) aCartPointA =
+ Handle(Geom_CartesianPoint)::DownCast( anAISPointA->Component());
- Handle(Geom_Point ) myGeomPointB = theAISPointB->Component();
- Handle(Geom_CartesianPoint ) myCartPointB= *((Handle(Geom_CartesianPoint)*)& theAISPointB);
- // Handle(Geom_CartesianPoint ) myCartPointB= *(Handle(Geom_CartesianPoint)*)& (theAISPointB->Component() ) ;
+ Handle(Geom_CartesianPoint ) aCartPointB =
+ Handle(Geom_CartesianPoint)::DownCast( anAISPointB->Component());
- Handle(Geom_Point ) myGeomPointBC= theAISPointC->Component();
- Handle(Geom_CartesianPoint ) myCartPointC= *((Handle(Geom_CartesianPoint)*)& theAISPointC);
- // Handle(Geom_CartesianPoint ) myCartPointC= *(Handle(Geom_CartesianPoint)*)& (theAISPointC->Component() ) ;
+ Handle(Geom_CartesianPoint ) aCartPointC =
+ Handle(Geom_CartesianPoint)::DownCast( anAISPointC->Component());
- // Verification que les 3 points sont bien differents.
- if (myCartPointB->X()==myCartPointA->X() && myCartPointB->Y()==myCartPointA->Y() && myCartPointB->Z()==myCartPointA->Z() ) {
+ // Verification that the three points are different
+ if(abs(aCartPointB->X()-aCartPointA->X())<=Precision::Confusion() &&
+ abs(aCartPointB->Y()-aCartPointA->Y())<=Precision::Confusion() &&
+ abs(aCartPointB->Z()-aCartPointA->Z())<=Precision::Confusion())
+ {
// B=A
- di<<"vplane error: same points"<<"\n";return 1;
+ std::cout<<"vplane error: same points"<<"\n";return 1;
}
- if (myCartPointC->X()==myCartPointA->X() && myCartPointC->Y()==myCartPointA->Y() && myCartPointC->Z()==myCartPointA->Z() ) {
+ if(abs(aCartPointC->X()-aCartPointA->X())<=Precision::Confusion() &&
+ abs(aCartPointC->Y()-aCartPointA->Y())<=Precision::Confusion() &&
+ abs(aCartPointC->Z()-aCartPointA->Z())<=Precision::Confusion())
+ {
// C=A
- di<<"vplane error: same points"<<"\n";return 1;
+ std::cout<<"vplane error: same points"<<"\n";return 1;
}
- if (myCartPointC->X()==myCartPointB->X() && myCartPointC->Y()==myCartPointB->Y() && myCartPointC->Z()==myCartPointB->Z() ) {
+ if(abs(aCartPointC->X()-aCartPointB->X())<=Precision::Confusion() &&
+ abs(aCartPointC->Y()-aCartPointB->Y())<=Precision::Confusion() &&
+ abs(aCartPointC->Z()-aCartPointB->Z())<=Precision::Confusion())
+ {
// C=B
- di<<"vplane error: same points"<<"\n";return 1;
+ std::cout<<"vplane error: same points"<<"\n";return 1;
}
- gp_Pnt A= myCartPointA->Pnt();
- gp_Pnt B= myCartPointB->Pnt();
- gp_Pnt C= myCartPointC->Pnt();
+ gp_Pnt A = aCartPointA->Pnt();
+ gp_Pnt B = aCartPointB->Pnt();
+ gp_Pnt C = aCartPointC->Pnt();
- // Construction de l'AIS_Plane
+ // Construction of AIS_Plane
GC_MakePlane MkPlane (A,B,C);
- Handle(Geom_Plane) myGeomPlane = MkPlane.Value();
- Handle(AIS_Plane) myAISPlane = new AIS_Plane(myGeomPlane );
- GetMapOfAIS().Bind (myAISPlane,name );
- TheAISContext()->Display(myAISPlane);
+ Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
+ Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane );
+ GetMapOfAIS().Bind (anAISPlane,aName );
+ TheAISContext()->Display(anAISPlane);
}
- // si le premier argument est un AIS_Axis 2
- // creation d'un plan orthogonal a l'axe passant par un point
- else if (theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==2 ) {
- // le deuxieme argument doit etre un AIS_Point
+ // The first argument is an AIS_Axis
+ // Creation of a plane orthogonal to the axis through a point
+ else if (aShapeA->Type()==AIS_KOI_Datum && aShapeA->Signature()==2 ) {
+ // The second argument should be an AIS_Point
if (argc!=4 || !GetMapOfAIS().IsBound2(argv[3] ) )
{
- di<<"vplane: error 2de name doesn't exist in the GetMapOfAIS()."<<"\n";
+ std::cout<<"vplane: error 2d name doesn't exist in the GetMapOfAIS()\n";
return 1;
}
- // on recupere la shape dans la map
- Handle(AIS_InteractiveObject) theShapeB =
+ // Get shape from map
+ Handle(AIS_InteractiveObject) aShapeB =
Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
- // si B n'est pas un AIS_Point
- if (theShapeB.IsNull() ||
- (!(theShapeB->Type()==AIS_KOI_Datum && theShapeB->Signature()==1)))
+ // If B is not an AIS_Point
+ if (aShapeB.IsNull() ||
+ (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
{
- di<<"vplane: error 2de object is expected to be an AIS_Point. "<<"\n";
+ std::cout<<"vplane: error 2d object is expected to be an AIS_Point\n";
return 1;
}
- // Traitement des objets A et B
- Handle(AIS_Axis) theAISAxisA= *(Handle(AIS_Axis)*)& theShapeA;
- Handle(AIS_Point) theAISPointB= *(Handle(AIS_Point)*)& theShapeB;
-
- Handle(Geom_Line ) myGeomLineA = theAISAxisA ->Component();
- Handle(Geom_Point) myGeomPointB= theAISPointB->Component() ;
+ // Treatment of objects A and B
+ Handle(AIS_Axis) anAISAxisA = Handle(AIS_Axis)::DownCast(aShapeA);
+ Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast(aShapeB);
- gp_Ax1 myAxis= myGeomLineA->Position();
- Handle(Geom_CartesianPoint ) myCartPointB= *(Handle(Geom_CartesianPoint )*)& myGeomPointB;
+ Handle(Geom_Line ) aGeomLineA = anAISAxisA ->Component();
+ Handle(Geom_Point) aGeomPointB = anAISPointB->Component() ;
- // Pas de moyens de verifier que le point B n'est pas sur l'axe
+ gp_Ax1 anAxis = aGeomLineA->Position();
+ Handle(Geom_CartesianPoint) aCartPointB =
+ Handle(Geom_CartesianPoint)::DownCast(aGeomPointB);
- gp_Dir D=myAxis.Direction();
- gp_Pnt B= myCartPointB->Pnt();
+ gp_Dir D =anAxis.Direction();
+ gp_Pnt B = aCartPointB->Pnt();
- // Construction de l'AIS_Plane
- Handle(Geom_Plane) myGeomPlane= new Geom_Plane(B,D);
- Handle(AIS_Plane) myAISPlane = new AIS_Plane(myGeomPlane,B );
- GetMapOfAIS().Bind (myAISPlane,name );
- TheAISContext()->Display(myAISPlane);
+ // Construction of AIS_Plane
+ Handle(Geom_Plane) aGeomPlane = new Geom_Plane(B,D);
+ Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane,B );
+ GetMapOfAIS().Bind (anAISPlane,aName );
+ TheAISContext()->Display(anAISPlane);
}
- // Si le premier argument est un AIS_Plane 7
- // Creation d'un Plan parallele a ce plan passant par le point
- else if (theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==7 ) {
- // le deuxieme argument doit etre un AISPoint
- if (argc!=4 || !GetMapOfAIS().IsBound2(argv[3] ) ) {
- di<<"vplane: error 2de name doesn't exist in the GetMapOfAIS()."<<"\n";
+ // The first argumnet is an AIS_Plane
+ // Creation of a plane parallel to the plane passing through the point
+ else if (aShapeA->Type()==AIS_KOI_Datum && aShapeA->Signature()==7)
+ {
+ // The second argument should be an AIS_Point
+ if (argc!=4 || !GetMapOfAIS().IsBound2(argv[3]))
+ {
+ std::cout<<"vplane: error 2d name doesn't exist in the GetMapOfAIS()\n";
return 1;
}
- // on recupere la shape dans la map
- Handle(AIS_InteractiveObject) theShapeB =
+ // Get shape from map
+ Handle(AIS_InteractiveObject) aShapeB =
Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3]));
- // si B n'est pas un AIS_Point
- if (theShapeB.IsNull() ||
- (!(theShapeB->Type()==AIS_KOI_Datum && theShapeB->Signature()==1)))
+ // B should be an AIS_Point
+ if (aShapeB.IsNull() ||
+ (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1)))
{
- di<<"vplane: error 2de object is expected to be an AIS_Point. "<<"\n";
+ std::cout<<"vplane: error 2d object is expected to be an AIS_Point\n";
return 1;
}
- // Traitement des objets A et B
- Handle(AIS_Plane) theAISPlaneA= *(Handle(AIS_Plane)*)& theShapeA;
- Handle(AIS_Point) theAISPointB= *(Handle(AIS_Point)*)& theShapeB;
-
- Handle (Geom_Plane) theNewGeomPlane= theAISPlaneA->Component();
- Handle(Geom_Point) myGeomPointB= theAISPointB->Component() ;
+ // Treatment of objects A and B
+ Handle(AIS_Plane) anAISPlaneA = Handle(AIS_Plane)::DownCast(aShapeA);
+ Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast(aShapeB);
- Handle(Geom_CartesianPoint ) myCartPointB= *(Handle(Geom_CartesianPoint )*)& myGeomPointB;
- gp_Pnt B= myCartPointB->Pnt();
+ Handle(Geom_Plane) aNewGeomPlane= anAISPlaneA->Component();
+ Handle(Geom_Point) aGeomPointB = anAISPointB->Component();
- // Construction de l'AIS_Plane
- Handle(AIS_Plane) myAISPlane = new AIS_Plane(theNewGeomPlane,B );
- GetMapOfAIS().Bind (myAISPlane,name );
- TheAISContext()->Display(myAISPlane);
+ Handle(Geom_CartesianPoint) aCartPointB =
+ Handle(Geom_CartesianPoint)::DownCast(aGeomPointB);
+ gp_Pnt B= aCartPointB->Pnt();
+ // Construction of an AIS_Plane
+ Handle(AIS_Plane) anAISPlane = new AIS_Plane(aNewGeomPlane, B);
+ GetMapOfAIS().Bind (anAISPlane, aName);
+ TheAISContext()->Display(anAISPlane);
+ }
+ // Error
+ else
+ {
+ std::cout<<"vplane: error 1st object is not an AIS\n";
+ return 1;
}
- // Sinon erreur
- else {di<<"vplane: error 1st object is not an AIS. "<<"\n";return 1;}
-
}
-
- // Il n'y a pas d'arguments
- else {
-
- // Fonction vplane
- // Teste le constructeur AIS_Plane::AIS_Plane(Geom_Plane, Standard_Boolean )
- if (!strcasecmp(argv[0] ,"vplane" ) ) {
+ // There are no arguments
+ else
+ {
+ // Function vplane
+ // Test the constructor AIS_Plane::AIS_Plane(Geom_Plane, Standard_Boolean )
+ if (!strcasecmp(argv[0], "vplane"))
+ {
TheAISContext()->OpenLocalContext();
- myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
+ aCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
- // Active les modes Vertex, Edge et Face
- TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
- TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
- TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
- di<<"Select a vertex, a face or an edge. "<<"\n";
+ // Active modes Vertex, Edge and Face
+ TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1));
+ TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2));
+ TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4));
+ std::cout<<"Select a vertex, a face or an edge\n";
- // Boucle d'attente waitpick.
+ // Wait for picking
Standard_Integer argcc = 5;
const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
const char **argvv = (const char **) buff;
while (ViewerMainLoop( argcc, argvv) ) { }
- // fin de la boucle
+ // end of the loop
- TopoDS_Shape ShapeA;
- for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
- ShapeA = TheAISContext()->SelectedShape();
+ TopoDS_Shape aShapeA;
+ for (TheAISContext()->InitSelected();
+ TheAISContext()->MoreSelected();
+ TheAISContext()->NextSelected())
+ {
+ aShapeA = TheAISContext()->SelectedShape();
}
- // ShapeA est un Vertex
- if (ShapeA.ShapeType()==TopAbs_VERTEX ) {
- TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
- di<<" Select an edge or a different vertex."<<"\n";
+ // aShapeA is a Vertex
+ if (aShapeA.ShapeType()==TopAbs_VERTEX )
+ {
+ TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
+ std::cout<<" Select an edge or a different vertex\n";
- // Boucle d'attente waitpick.
+ // Wait for picking
Standard_Integer argccc = 5;
const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
const char **argvvv = (const char **) bufff;
while (ViewerMainLoop( argccc, argvvv) ) { }
- // fin de la boucle
+ // end of the loop
- TopoDS_Shape ShapeB;
- for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
- ShapeB = TheAISContext()->SelectedShape();
+ TopoDS_Shape aShapeB;
+ for (TheAISContext()->InitSelected();
+ TheAISContext()->MoreSelected();
+ TheAISContext()->NextSelected())
+ {
+ aShapeB = TheAISContext()->SelectedShape();
}
- // ShapeB est un Vertex
- if (ShapeB.ShapeType()==TopAbs_VERTEX ) {
- // Si A et B sont le meme point
- if (ShapeB.IsSame(ShapeA) ) {di<<" vplane: error, same points selected"<<"\n";return 1; }
- TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2) );
- di<<" Select a different vertex."<<"\n";
+ // aShapeB is a Vertex
+ if (aShapeB.ShapeType()==TopAbs_VERTEX)
+ {
+ // A and B are the same
+ if (aShapeB.IsSame(aShapeA))
+ {
+ std::cout<<" vplane: error, same points selected\n";
+ return 1;
+ }
+ TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2));
+ std::cout<<" Select a different vertex\n";
- // Boucle d'attente waitpick.
+ // Wait for picking
Standard_Integer argcccc = 5;
const char *buffff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
const char **argvvvv = (const char **) buffff;
while (ViewerMainLoop( argcccc, argvvvv) ) { }
- // fin de la boucle
+ // end of the loop
- TopoDS_Shape ShapeC;
- for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
- ShapeC = TheAISContext()->SelectedShape();
+ TopoDS_Shape aShapeC;
+ for (TheAISContext()->InitSelected();
+ TheAISContext()->MoreSelected();
+ TheAISContext()->NextSelected())
+ {
+ aShapeC = TheAISContext()->SelectedShape();
+ }
+ // aShapeC is the same as A or B
+ if (aShapeC.IsSame(aShapeA)||aShapeC.IsSame(aShapeB))
+ {
+ std::cout<<" vplane: error, same points selected\n";
+ return 1;
}
- // ShapeC est aussi un vertex...
- if (ShapeC.IsSame(ShapeA)||ShapeC.IsSame(ShapeB) ) {di<<" vplane: error, same points selected"<<"\n";return 1; }
-
- // Fermeture du contexte local
- TheAISContext()->CloseLocalContext(myCurrentIndex);
-
- // Construction du plane
- gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA ) );
- gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB ) );
- gp_Pnt C=BRep_Tool::Pnt(TopoDS::Vertex(ShapeC ) );
- GC_MakePlane MkPlane(A,B,C);
- Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
- Handle(AIS_Plane) myAISPlane=new AIS_Plane (theGeomPlane );
- GetMapOfAIS().Bind (myAISPlane ,name );
- TheAISContext()->Display(myAISPlane);
+ // Close the local context
+ TheAISContext()->CloseLocalContext(aCurrentIndex);
+
+ // Construction of plane
+ gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(aShapeA));
+ gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(aShapeB));
+ gp_Pnt C = BRep_Tool::Pnt(TopoDS::Vertex(aShapeC));
+ GC_MakePlane MkPlane(A, B, C);
+ Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
+ Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
+ GetMapOfAIS().Bind (anAISPlane, aName);
+ TheAISContext()->Display(anAISPlane);
}
- // ShapeB est un edge
- else {
- // il s'agit de verifier que le vertex ShapeA n'est pas sur l'edge ShapeB
- TopoDS_Edge EdgeB=TopoDS::Edge(ShapeB);
- TopoDS_Vertex VertA=TopoDS::Vertex(ShapeA);
-
- BRepExtrema_ExtPC OrthoProj (VertA, EdgeB );
- if (OrthoProj.SquareDistance(1)<1e-6 ) {
- // Le vertex est sur l'edge
- di<<" vplane: error point is on the edge."<<"\n";return 1;
- }
- else {
- // le vertex n'appartient pes a l'edge on peut construire le plane
- // Fermeture du contexte local
- TheAISContext()->CloseLocalContext(myCurrentIndex);
- // Construction du plane
- gp_Pnt A=BRep_Tool::Pnt(VertA );
- TopoDS_Vertex VBa,VBb;
- TopExp::Vertices(EdgeB ,VBa ,VBb );
- gp_Pnt Ba=BRep_Tool::Pnt(VBa);
- gp_Pnt Bb=BRep_Tool::Pnt(VBb);
- GC_MakePlane MkPlane (A,Ba,Bb);
- Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
- Handle(AIS_Plane) myAISPlane=new AIS_Plane (theGeomPlane );
- GetMapOfAIS().Bind (myAISPlane ,name );
- TheAISContext()->Display(myAISPlane);
+ // ShapeB is an edge
+ else
+ {
+ // Verify that the vertex is not on the edge ShapeB
+ TopoDS_Edge anEdgeB = TopoDS::Edge(aShapeB);
+ TopoDS_Vertex aVertA = TopoDS::Vertex(aShapeA);
+ BRepExtrema_ExtPC OrthoProj(aVertA, anEdgeB);
+ if (OrthoProj.SquareDistance(1)<Precision::Approximation())
+ {
+ // The vertex is on the edge
+ std::cout<<" vplane: error point is on the edge\n";
+ return 1;
+ }
+ else
+ {
+ // Close the local context
+ TheAISContext()->CloseLocalContext(aCurrentIndex);
+ // Construction of plane
+ gp_Pnt A = BRep_Tool::Pnt(aVertA);
+ TopoDS_Vertex aVBa, aVBb;
+ TopExp::Vertices(anEdgeB ,aVBa ,aVBb);
+ gp_Pnt aBa = BRep_Tool::Pnt(aVBa);
+ gp_Pnt aBb = BRep_Tool::Pnt(aVBb);
+ GC_MakePlane MkPlane (A, aBa, aBb);
+ Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
+ Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
+ GetMapOfAIS().Bind (anAISPlane, aName);
+ TheAISContext()->Display(anAISPlane);
}
-
}
-
}
- // ShapeA est un edge
- else if (ShapeA.ShapeType()==TopAbs_EDGE ) {
-
- TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
- TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2) );
- di<<" Select a vertex that don't belong to the edge."<<"\n";
+ // aShapeA is an edge
+ else if (aShapeA.ShapeType()==TopAbs_EDGE)
+ {
+ TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
+ TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2));
+ std::cout<<" Select a vertex that don't belong to the edge\n";
- // Boucle d'attente waitpick.
+ // Wait for picking
Standard_Integer argccc = 5;
const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
const char **argvvv = (const char **) bufff;
while (ViewerMainLoop( argccc, argvvv) ) { }
- // fin de la boucle
+ // end of the loop
- TopoDS_Shape ShapeB;
- for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
- ShapeB = TheAISContext()->SelectedShape();
+ TopoDS_Shape aShapeB;
+ for (TheAISContext()->InitSelected();
+ TheAISContext()->MoreSelected();
+ TheAISContext()->NextSelected())
+ {
+ aShapeB = TheAISContext()->SelectedShape();
}
- // ShapeB est forcement un Vertex
- // On verifie que le vertex ShapeB n'est pas sur l'edge ShapeA
- TopoDS_Edge EdgeA=TopoDS::Edge(ShapeA);
- TopoDS_Vertex VertB=TopoDS::Vertex(ShapeB);
-
- BRepExtrema_ExtPC OrthoProj (VertB,EdgeA );
- if (OrthoProj.SquareDistance(1)<1e-6) {
- // Le vertex est sur l'edge
- di<<" vplane: error point is on the edge."<<"\n";return 1;
+ // aShapeB should be a Vertex
+ // Check that the vertex aShapeB is not on the edge
+ TopoDS_Edge anEdgeA = TopoDS::Edge(aShapeA);
+ TopoDS_Vertex aVertB = TopoDS::Vertex(aShapeB);
+
+ BRepExtrema_ExtPC OrthoProj (aVertB, anEdgeA);
+ if (OrthoProj.SquareDistance(1)<Precision::Approximation())
+ {
+ // The vertex is on the edge
+ std::cout<<" vplane: error point is on the edge\n";
+ return 1;
}
- else {
- // le vertex n'appartient pas a l'edge on peut construire le plane
- // Fermeture du contexte local
- TheAISContext()->CloseLocalContext(myCurrentIndex);
- // Construction du plane
- gp_Pnt B=BRep_Tool::Pnt(VertB );
- TopoDS_Vertex VAa,VAb;
- TopExp::Vertices(EdgeA ,VAa ,VAb );
- gp_Pnt Aa=BRep_Tool::Pnt(VAa);
- gp_Pnt Ab=BRep_Tool::Pnt(VAb);
+ else
+ {
+ // Close the local context
+ TheAISContext()->CloseLocalContext(aCurrentIndex);
+ // Construction of plane
+ gp_Pnt B = BRep_Tool::Pnt(aVertB);
+ TopoDS_Vertex aVAa, aVAb;
+ TopExp::Vertices(anEdgeA, aVAa, aVAb);
+ gp_Pnt Aa = BRep_Tool::Pnt(aVAa);
+ gp_Pnt Ab = BRep_Tool::Pnt(aVAb);
GC_MakePlane MkPlane (B,Aa,Ab);
- Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
- Handle(AIS_Plane) myAISPlane=new AIS_Plane (theGeomPlane );
- GetMapOfAIS().Bind (myAISPlane ,name );
- TheAISContext()->Display(myAISPlane);
-
+ Handle(Geom_Plane) aGeomPlane = MkPlane.Value();
+ Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane);
+ GetMapOfAIS().Bind (anAISPlane ,aName);
+ TheAISContext()->Display(anAISPlane);
}
-
-
}
- // ShapeA est une Face
- else {
- // Fermeture du contexte local: Plus rien a selectionner
- TheAISContext()->CloseLocalContext(myCurrentIndex);
- // Construction du plane
- TopoDS_Face myFace=TopoDS::Face(ShapeA);
- BRepAdaptor_Surface mySurface (myFace, Standard_False );
- if (mySurface.GetType()==GeomAbs_Plane ) {
- gp_Pln myPlane=mySurface.Plane();
- Handle(Geom_Plane) theGeomPlane=new Geom_Plane (myPlane );
- Handle(AIS_Plane) myAISPlane=new AIS_Plane (theGeomPlane );
- GetMapOfAIS().Bind (myAISPlane ,name );
- TheAISContext()->Display(myAISPlane);
-
+ // aShapeA is a Face
+ else
+ {
+ // Close the local context: nothing to select
+ TheAISContext()->CloseLocalContext(aCurrentIndex);
+ // Construction of plane
+ TopoDS_Face aFace = TopoDS::Face(aShapeA);
+ BRepAdaptor_Surface aSurface (aFace, Standard_False);
+ if (aSurface.GetType()==GeomAbs_Plane)
+ {
+ gp_Pln aPlane = aSurface.Plane();
+ Handle(Geom_Plane) aGeomPlane = new Geom_Plane(aPlane);
+ Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane);
+ GetMapOfAIS().Bind (anAISPlane, aName);
+ TheAISContext()->Display(anAISPlane);
}
- else {
- di<<" vplane: error"<<"\n";return 1;
+ else
+ {
+ std::cout<<" vplane: error\n";
+ return 1;
}
-
}
-
}
- // Fonction vPlanePara
+ // Function vPlanePara
// ===================
- // teste le constructeur AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt )
- else if (!strcasecmp(argv[0] ,"vplanepara" )) {
-
+ // test the constructor AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt)
+ else if (!strcasecmp(argv[0], "vplanepara"))
+ {
TheAISContext()->OpenLocalContext();
- myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
+ aCurrentIndex = TheAISContext()->IndexOfCurrentLocal();
- // Active les modes Vertex et Face
- TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
- TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
- di<<" Select a vertex or a face."<<"\n";
+ // Activate modes Vertex and Face
+ TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1));
+ TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4));
+ std::cout<<" Select a vertex or a face\n";
- // Boucle d'attente waitpick.
+ // Wait for picking
Standard_Integer argcc = 5;
const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
const char **argvv = (const char **) buff;
while (ViewerMainLoop( argcc, argvv) ) { }
- // fin de la boucle
+ // end of the loop
- TopoDS_Shape ShapeA;
- for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
- ShapeA = TheAISContext()->SelectedShape();
+ TopoDS_Shape aShapeA;
+ for (TheAISContext()->InitSelected();
+ TheAISContext()->MoreSelected();
+ TheAISContext()->NextSelected())
+ {
+ aShapeA = TheAISContext()->SelectedShape();
}
- if (ShapeA.ShapeType()==TopAbs_VERTEX ) {
- // ShapeA est un vertex
- // On desactive le mode Vertex
- TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(1) );
- di<<" Select a face."<<"\n";
+ if (aShapeA.ShapeType()==TopAbs_VERTEX )
+ {
+ // aShapeA is a vertex
+ // Deactivate the mode Vertex
+ TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(1));
+ std::cout<<" Select a face\n";
- // Boucle d'attente waitpick.
+ // Wait for picking
Standard_Integer argccc = 5;
const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
const char **argvvv = (const char **) bufff;
while (ViewerMainLoop( argccc, argvvv) ) { }
- // fin de la boucle
+ // end of the loop
- TopoDS_Shape ShapeB;
- for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
- // Le vertex ShapeA peut etre dans la Face ShapeB
- ShapeB = TheAISContext()->SelectedShape();
+ TopoDS_Shape aShapeB;
+ for (TheAISContext()->InitSelected();
+ TheAISContext()->MoreSelected();
+ TheAISContext()->NextSelected())
+ {
+ // A vertex ShapeA can be on Face ShapeB
+ aShapeB = TheAISContext()->SelectedShape();
}
- // Fermeture du context local
- TheAISContext()->CloseLocalContext(myCurrentIndex);
-
- // Construction du plane
- gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA ) );
-
- TopoDS_Face myFace=TopoDS::Face(ShapeB);
- BRepAdaptor_Surface mySurface (myFace, Standard_False );
- if (mySurface.GetType()==GeomAbs_Plane ) {
- gp_Pln myPlane=mySurface.Plane();
- // construit un plan parallele a theGeomPlane passant par A
- myPlane.SetLocation(A);
- Handle(Geom_Plane) theGeomPlane=new Geom_Plane (myPlane );
- Handle(AIS_Plane) myAISPlane=new AIS_Plane (theGeomPlane ,A );
- GetMapOfAIS().Bind (myAISPlane ,name );
- TheAISContext()->Display(myAISPlane);
+ // Close the local context
+ TheAISContext()->CloseLocalContext(aCurrentIndex);
+ // Construction of plane
+ gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(aShapeA));
+
+ TopoDS_Face aFace = TopoDS::Face(aShapeB);
+ BRepAdaptor_Surface aSurface (aFace, Standard_False);
+ if (aSurface.GetType()==GeomAbs_Plane )
+ {
+ gp_Pln aPlane = aSurface.Plane();
+ // Construct a plane parallel to aGeomPlane through A
+ aPlane.SetLocation(A);
+ Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
+ Handle(AIS_Plane) aAISPlane = new AIS_Plane (aGeomPlane, A);
+ GetMapOfAIS().Bind (aAISPlane ,aName);
+ TheAISContext()->Display(aAISPlane);
}
- else {
- di<<" vplane: error"<<"\n";return 1;
+ else
+ {
+ std::cout<<" vplanepara: error\n";
+ return 1;
}
-
}
- else{
- // ShapeA est une Face
- // On desactive le mode Face
- TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
- di<<" Select a vertex."<<"\n";
+ else
+ {
+ // ShapeA is a Face
+ // Deactive the mode Face
+ TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
+ std::cout<<" Select a vertex\n";
- // Boucle d'attente waitpick.
+ // Wait for picking
Standard_Integer argccc = 5;
const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
const char **argvvv = (const char **) bufff;
while (ViewerMainLoop( argccc, argvvv) ) { }
- // fin de la boucle
+ // end of the loop
- TopoDS_Shape ShapeB;
- for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
- // Le vertex ShapeB peut etre dans la Face ShapeA
- ShapeB = TheAISContext()->SelectedShape();
+ TopoDS_Shape aShapeB;
+ for (TheAISContext()->InitSelected();
+ TheAISContext()->MoreSelected();
+ TheAISContext()->NextSelected())
+ {
+ // A vertex ShapeB can be on Face ShapeA
+ aShapeB = TheAISContext()->SelectedShape();
}
- // Fermeture du context local
- TheAISContext()->CloseLocalContext(myCurrentIndex);
-
- // Construction du plane
- gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB ) );
-
- TopoDS_Face myFace=TopoDS::Face(ShapeA);
- BRepAdaptor_Surface mySurface (myFace, Standard_False );
- if (mySurface.GetType()==GeomAbs_Plane ) {
- gp_Pln myPlane=mySurface.Plane();
- myPlane.SetLocation(B);
- Handle(Geom_Plane) theGeomPlane=new Geom_Plane (myPlane );
- // construit un plan parallele a theGeomPlane passant par B
- Handle(AIS_Plane) myAISPlane=new AIS_Plane (theGeomPlane ,B );
- GetMapOfAIS().Bind (myAISPlane ,name );
- TheAISContext()->Display(myAISPlane);
+ // Close the local context
+ TheAISContext()->CloseLocalContext(aCurrentIndex);
+ // Construction of plane
+ gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(aShapeB));
+
+ TopoDS_Face aFace=TopoDS::Face(aShapeA);
+ BRepAdaptor_Surface aSurface (aFace, Standard_False);
+ if (aSurface.GetType()==GeomAbs_Plane )
+ {
+ gp_Pln aPlane = aSurface.Plane();
+ aPlane.SetLocation(B);
+ Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
+ // Construct a plane parallel to aGeomPlane through B
+ Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, B);
+ GetMapOfAIS().Bind (anAISPlane, aName);
+ TheAISContext()->Display(anAISPlane);
}
- else {
- di<<" vplane: error"<<"\n";return 1;
+ else
+ {
+ std::cout<<" vplanepara: error"<<"\n";return 1;
}
-
}
-
}
- // Fonction vplaneortho
+ // Function vplaneortho
// ====================
- // teste le constructeur AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt,gp_Pnt,gp_Pnt)
- else {
-
+ // test the constructor AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt,gp_Pnt,gp_Pnt)
+ else
+ {
TheAISContext()->OpenLocalContext();
- myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
+ aCurrentIndex = TheAISContext()->IndexOfCurrentLocal();
- // Active les modes Edge et Face
- TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
- TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
- di<<" Select a face and an edge coplanar."<<"\n";
+ // Activate the modes Edge and Face
+ TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2));
+ TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4));
+ std::cout<<" Select a face and an edge coplanar\n";
- // Boucle d'attente waitpick.
+ // Wait for picking
Standard_Integer argcc = 5;
const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
const char **argvv = (const char **) buff;
while (ViewerMainLoop( argcc, argvv) ) { }
- // fin de la boucle
+ // end of the loop
- TopoDS_Shape ShapeA;
- for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
- ShapeA = TheAISContext()->SelectedShape();
+ TopoDS_Shape aShapeA;
+ for (TheAISContext()->InitSelected();
+ TheAISContext()->MoreSelected();
+ TheAISContext()->NextSelected())
+ {
+ aShapeA = TheAISContext()->SelectedShape();
}
- if (ShapeA.ShapeType()==TopAbs_EDGE ) {
- // ShapeA est un edge, on desactive le mode edge...
- TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2) );
- di<<" Select a face."<<"\n";
+ if (aShapeA.ShapeType()==TopAbs_EDGE )
+ {
+ // ShapeA is an edge, deactivate the mode Edge...
+ TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2));
+ std::cout<<" Select a face\n";
- // Boucle d'attente waitpick.
+ // Wait for picking
Standard_Integer argccc = 5;
const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
const char **argvvv = (const char **) bufff;
while (ViewerMainLoop( argccc, argvvv) ) { }
- // fin de la boucle
+ // end of the loop
- TopoDS_Shape ShapeB;
- for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
- // L'edge ShapeA peut etre dans la Face ShapeB
- ShapeB = TheAISContext()->SelectedShape();
+ TopoDS_Shape aShapeB;
+ for (TheAISContext()->InitSelected();
+ TheAISContext()->MoreSelected();
+ TheAISContext()->NextSelected())
+ {
+ // Edge ShapeA can be on Face ShapeB
+ aShapeB = TheAISContext()->SelectedShape();
}
- // Fermeture du context local
- TheAISContext()->CloseLocalContext(myCurrentIndex);
+ // Close the local context
+ TheAISContext()->CloseLocalContext(aCurrentIndex);
- // Construction du plane
- TopoDS_Edge EdgeA=TopoDS::Edge(ShapeA);
- TopoDS_Vertex VAa,VAb;
- // vi
- TopExp::Vertices(EdgeA ,VAa ,VAb );
- gp_Pnt Aa=BRep_Tool::Pnt(VAa);
- gp_Pnt Ab=BRep_Tool::Pnt(VAb);
- gp_Vec ab (Aa,Ab);
+ // Construction of plane
+ TopoDS_Edge anEdgeA = TopoDS::Edge(aShapeA);
+ TopoDS_Vertex aVAa, aVAb;
+ TopExp::Vertices(anEdgeA, aVAa, aVAb);
+ gp_Pnt Aa = BRep_Tool::Pnt(aVAa);
+ gp_Pnt Ab = BRep_Tool::Pnt(aVAb);
+ gp_Vec ab (Aa,Ab);
gp_Dir Dab (ab);
- // Creation de mon axe de rotation
- gp_Ax1 myRotAxis (Aa,Dab);
-
- TopoDS_Face myFace=TopoDS::Face(ShapeB);
- // Il faut imperativement que l'edge soit parallele a la face
- // vi
- BRepExtrema_ExtPF myHauteurA (VAa , myFace );
- BRepExtrema_ExtPF myHauteurB (VAb , myFace );
- // on compare les deux hauteurs a la tolerance pres
- if ( fabs(sqrt(myHauteurA.SquareDistance(1)) - sqrt (myHauteurB.SquareDistance(1)) )>0.1 ) {
- // l'edge n'est pas parallele a la face
- di<<" vplaneOrtho error: l'edge n'est pas parallele a la face."<<"\n";return 1;
+ // Creation of rotation axis
+ gp_Ax1 aRotAxis (Aa,Dab);
+
+ TopoDS_Face aFace = TopoDS::Face(aShapeB);
+ // The edge must be parallel to the face
+ BRepExtrema_ExtPF aHeightA (aVAa, aFace);
+ BRepExtrema_ExtPF aHeightB (aVAb, aFace);
+ // Compare to heights
+ if (fabs(sqrt(aHeightA.SquareDistance(1)) - sqrt(aHeightB.SquareDistance(1)))
+ >Precision::Confusion())
+ {
+ // the edge is not parallel to the face
+ std::cout<<" vplaneortho error: the edge is not parallel to the face\n";
+ return 1;
}
- // l'edge est OK
- BRepAdaptor_Surface mySurface (myFace, Standard_False );
- if (mySurface.GetType()==GeomAbs_Plane ) {
- gp_Pln myPlane=mySurface.Plane();
- // On effectue une rotation d'1/2 tour autour de l'axe de rotation
- myPlane.Rotate(myRotAxis , M_PI/2 );
-
- Handle(Geom_Plane) theGeomPlane=new Geom_Plane (myPlane );
- // construit un plan parallele a theGeomPlane contenant l'edgeA (De centre le milieu de l'edgeA)
- gp_Pnt theMiddle ((Aa.X()+Ab.X() )/2 ,(Aa.Y()+Ab.Y() )/2 ,(Aa.Z()+Ab.Z() )/2 );
- Handle(AIS_Plane) myAISPlane=new AIS_Plane (theGeomPlane ,theMiddle );
- GetMapOfAIS().Bind (myAISPlane ,name );
- TheAISContext()->Display(myAISPlane);
-
+ // the edge is OK
+ BRepAdaptor_Surface aSurface (aFace, Standard_False);
+ if (aSurface.GetType()==GeomAbs_Plane)
+ {
+ gp_Pln aPlane = aSurface.Plane();
+ // It rotates a half turn round the axis of rotation
+ aPlane.Rotate(aRotAxis , M_PI/2);
+
+ Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
+ // constructed aGeomPlane parallel to a plane containing the edge (center mid-edge)
+ gp_Pnt aMiddle ((Aa.X()+Ab.X() )/2 ,(Aa.Y()+Ab.Y() )/2 ,(Aa.Z()+Ab.Z() )/2 );
+ Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, aMiddle);
+ GetMapOfAIS().Bind (anAISPlane, aName);
+ TheAISContext()->Display(anAISPlane);
}
- else {
- di<<" vplaneOrtho: error"<<"\n";return 1;
+ else
+ {
+ std::cout<<" vplaneortho: error\n";
+ return 1;
}
-
}
+ else
+ {
+ // ShapeA is a Face, deactive the mode Face.
+ TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4));
+ std::cout<<" Select an edge\n";
- else {
- // ShapeA est une Face, on desactive le mode face.
- TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
- di<<" Select an edge."<<"\n";
-
- // Boucle d'attente waitpick.
+ // Wait for picking
Standard_Integer argccc = 5;
const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
const char **argvvv = (const char **) bufff;
while (ViewerMainLoop( argccc, argvvv) ) { }
- // fin de la boucle
+ // end of the loop
- TopoDS_Shape ShapeB;
- for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
- // L'edge ShapeB peut etre dans la Face ShapeA
- ShapeB = TheAISContext()->SelectedShape();
+ TopoDS_Shape aShapeB;
+ for (TheAISContext()->InitSelected();
+ TheAISContext()->MoreSelected();
+ TheAISContext()->NextSelected())
+ {
+ // Edge ShapeB can be on Face ShapeA
+ aShapeB = TheAISContext()->SelectedShape();
}
-
- // Fermeture du context local
- TheAISContext()->CloseLocalContext(myCurrentIndex);
-
- // Construction du plane
- TopoDS_Edge EdgeB=TopoDS::Edge(ShapeB);
- TopoDS_Vertex VBa,VBb;
- TopExp::Vertices(EdgeB ,VBa ,VBb );
- gp_Pnt Ba=BRep_Tool::Pnt(VBa);
- gp_Pnt Bb=BRep_Tool::Pnt(VBb);
- gp_Vec ab (Ba,Bb);
+ // Close the local context
+ TheAISContext()->CloseLocalContext(aCurrentIndex);
+
+ // Construction of plane
+ TopoDS_Edge anEdgeB = TopoDS::Edge(aShapeB);
+ TopoDS_Vertex aVBa, aVBb;
+ TopExp::Vertices(anEdgeB, aVBa, aVBb);
+ gp_Pnt aBa = BRep_Tool::Pnt(aVBa);
+ gp_Pnt aBb = BRep_Tool::Pnt(aVBb);
+ gp_Vec ab (aBa,aBb);
gp_Dir Dab (ab);
- // Creation de mon axe de rotation
- gp_Ax1 myRotAxis (Ba,Dab);
-
- TopoDS_Face myFace=TopoDS::Face(ShapeA);
- // Il faut imperativement que l'edge soit parallele a la face
- BRepExtrema_ExtPF myHauteurA (VBa , myFace );
- BRepExtrema_ExtPF myHauteurB (VBb , myFace );
- // on compare les deux hauteurs a la tolerance pres
- if ( fabs(sqrt(myHauteurA.SquareDistance(1)) - sqrt(myHauteurB.SquareDistance(1)) )>0.1 ) {
- // l'edge n'est pas parallele a la face
- di<<" vplaneOrtho error: l'edge n'est pas parallele a la face."<<"\n";return 1;
+ // Creation of rotation axe
+ gp_Ax1 aRotAxis (aBa,Dab);
+
+ TopoDS_Face aFace = TopoDS::Face(aShapeA);
+ // The edge must be parallel to the face
+ BRepExtrema_ExtPF aHeightA (aVBa, aFace);
+ BRepExtrema_ExtPF aHeightB (aVBb, aFace);
+ // Comparing the two heights
+ if (fabs(sqrt(aHeightA.SquareDistance(1)) - sqrt(aHeightB.SquareDistance(1)))
+ >Precision::Confusion())
+ {
+ // the edge is not parallel to the face
+ std::cout<<" vplaneortho error: the edge is not parallel to the face\n";
+ return 1;
}
- // l'edge est OK
- BRepAdaptor_Surface mySurface (myFace, Standard_False );
- if (mySurface.GetType()==GeomAbs_Plane ) {
- gp_Pln myPlane=mySurface.Plane();
- // On effectue une rotation d'1/2 tour autour de l'axe de rotation
- myPlane.Rotate(myRotAxis , M_PI/2 );
- Handle(Geom_Plane) theGeomPlane=new Geom_Plane (myPlane );
- // construit un plan parallele a theGeomPlane contenant l'edgeA (De centre le milieu de l'edgeA)
- gp_Pnt theMiddle ((Ba.X()+Bb.X() )/2 , (Ba.Y()+Bb.Y() )/2 , (Ba.Z()+Bb.Z() )/2 );
- Handle(AIS_Plane) myAISPlane=new AIS_Plane (theGeomPlane ,theMiddle );
- GetMapOfAIS().Bind (myAISPlane ,name );
- TheAISContext()->Display(myAISPlane);
-
+ // The edge is OK
+ BRepAdaptor_Surface aSurface (aFace, Standard_False);
+ if (aSurface.GetType()==GeomAbs_Plane)
+ {
+ gp_Pln aPlane = aSurface.Plane();
+ // It rotates a half turn round the axis of rotation
+ aPlane.Rotate(aRotAxis , M_PI/2);
+ Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
+ // constructed aGeomPlane parallel to a plane containing the edge theGeomPlane (center mid-edge)
+ gp_Pnt aMiddle ((aBa.X()+aBb.X() )/2 , (aBa.Y()+aBb.Y() )/2 , (aBa.Z()+aBb.Z() )/2 );
+ Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, aMiddle);
+ GetMapOfAIS().Bind (anAISPlane ,aName);
+ TheAISContext()->Display(anAISPlane);
}
- else {
- di<<" vplaneOrtho: error"<<"\n";return 1;
+ else
+ {
+ std::cout<<" vplaneortho: error\n";
+ return 1;
}
-
}
-
}
-
}
return 0;
-
}
// Activate selection mode for vertices and faces
TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
- std::cout << " Select a vertex or a face.\n";
+ std::cout << " Select a vertex or a face\n";
// Wait for picking
Standard_Integer argcc = 5;
if (ShapeA.ShapeType() == TopAbs_VERTEX )
{
TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
- std::cout << " Select a different vertex.\n";
+ std::cout << " Select a different vertex\n";
TopoDS_Shape ShapeB;
do
} while(ShapeB.IsSame(ShapeA) );
// Selection of ShapeC
- std::cout << " Select the last vertex.\n";
+ std::cout << " Select the last vertex\n";
TopoDS_Shape ShapeC;
do
{
}
// Shape is a face
- else
+ else
{
- std::cout << " Select a vertex (in your face).\n";
+ std::cout << " Select a vertex (in your face)\n";
TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
TopoDS_Shape ShapeB;
return 0;
}
+
//===============================================================================================
//function : VDrawText
//author : psn
return 0;
}
+//==========================================================================
+//class : Triangle
+//purpose : creates Triangle based on AIS_InteractiveObject.
+// This class was implemented for testing Select3D_SensitiveTriangle
+//===========================================================================
+DEFINE_STANDARD_HANDLE(Triangle, AIS_InteractiveObject)
+class Triangle: public AIS_InteractiveObject
+{
+public:
+ // CASCADE RTTI
+ DEFINE_STANDARD_RTTI(FilledCircle);
+ Triangle (const gp_Pnt& theP1,
+ const gp_Pnt& theP2,
+ const gp_Pnt& theP3);
+protected:
+ void Compute ( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
+ const Handle(Prs3d_Presentation)& thePresentation,
+ const Standard_Integer theMode);
+
+ void ComputeSelection ( const Handle(SelectMgr_Selection)& theSelection,
+ const Standard_Integer theMode);
+private:
+ gp_Pnt myPoint1;
+ gp_Pnt myPoint2;
+ gp_Pnt myPoint3;
+};
+IMPLEMENT_STANDARD_HANDLE(Triangle, AIS_InteractiveObject)
+IMPLEMENT_STANDARD_RTTIEXT(Triangle, AIS_InteractiveObject)
+
+Triangle::Triangle (const gp_Pnt& theP1,
+ const gp_Pnt& theP2,
+ const gp_Pnt& theP3)
+{
+ myPoint1 = theP1;
+ myPoint2 = theP2;
+ myPoint3 = theP3;
+}
+
+void Triangle::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
+ const Handle(Prs3d_Presentation)& thePresentation,
+ const Standard_Integer theMode)
+{
+ thePresentation->Clear();
+
+ BRepBuilderAPI_MakeEdge anEdgeMaker1(myPoint1, myPoint2),
+ anEdgeMaker2(myPoint2, myPoint3),
+ anEdgeMaker3(myPoint3, myPoint1);
+
+ TopoDS_Edge anEdge1 = anEdgeMaker1.Edge(),
+ anEdge2 = anEdgeMaker2.Edge(),
+ anEdge3 = anEdgeMaker3.Edge();
+ if(anEdge1.IsNull() || anEdge2.IsNull() || anEdge3.IsNull())
+ return;
+
+ BRepBuilderAPI_MakeWire aWireMaker(anEdge1, anEdge2, anEdge3);
+ TopoDS_Wire aWire = aWireMaker.Wire();
+ if(aWire.IsNull()) return;
+
+ BRepBuilderAPI_MakeFace aFaceMaker(aWire);
+ TopoDS_Face aFace = aFaceMaker.Face();
+ if(aFace.IsNull()) return;
+
+ StdPrs_ShadedShape::Add(thePresentation, aFace, myDrawer);
+}
+
+void Triangle::ComputeSelection(const Handle(SelectMgr_Selection)& theSelection,
+ const Standard_Integer theMode)
+{
+ Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner(this);
+ Handle(Select3D_SensitiveTriangle) aSensTriangle =
+ new Select3D_SensitiveTriangle(anEntityOwner, myPoint1, myPoint2, myPoint3);
+ theSelection->Add(aSensTriangle);
+}
+
+//===========================================================================
+//function : VTriangle
+//Draw arg : vtriangle Name PointName PointName PointName
+//purpose : creates and displays Triangle
+//===========================================================================
+
+//function: IsPoint
+//purpose : checks if the object with theName is AIS_Point,
+// if yes initialize thePoint from MapOfAIS
+Standard_Boolean IsPoint (const TCollection_AsciiString& theName,
+ Handle(AIS_Point)& thePoint)
+{
+ Handle(AIS_InteractiveObject) anObject =
+ Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(theName));
+ if(anObject.IsNull() ||
+ anObject->Type() != AIS_KOI_Datum ||
+ anObject->Signature() != 1)
+ {
+ return Standard_False;
+ }
+ thePoint = Handle(AIS_Point)::DownCast(anObject);
+ if(thePoint.IsNull())
+ return Standard_False;
+ return Standard_True;
+}
+
+//function: IsMatch
+//purpose: checks if thePoint1 is equal to thePoint2
+Standard_Boolean IsMatch (const Handle(Geom_CartesianPoint)& thePoint1,
+ const Handle(Geom_CartesianPoint)& thePoint2)
+{
+ if(abs(thePoint1->X()-thePoint2->X()) <= Precision::Confusion() &&
+ abs(thePoint1->Y()-thePoint2->Y()) <= Precision::Confusion() &&
+ abs(thePoint1->Z()-thePoint2->Z()) <= Precision::Confusion())
+ {
+ return Standard_True;
+ }
+ return Standard_False;
+}
+
+static Standard_Integer VTriangle (Draw_Interpretor& di,
+ Standard_Integer argc,
+ const char ** argv)
+{
+ // Check arguments
+ if (argc != 5)
+ {
+ std::cout<<"vtriangle error: expects 4 argumnets\n";
+ return 1; // TCL_ERROR
+ }
+
+ TheAISContext()->CloseAllContexts();
+
+ // Get and check values
+ TCollection_AsciiString aName(argv[1]);
+
+ Handle(AIS_Point) aPoint1, aPoint2, aPoint3;
+ if (!IsPoint(argv[2], aPoint1))
+ {
+ std::cout<<"vtriangle error: the 2nd argument must be a point\n";
+ return 1; // TCL_ERROR
+ }
+ if (!IsPoint(argv[3], aPoint2))
+ {
+ std::cout<<"vtriangle error: the 3d argument must be a point\n";
+ return 1; // TCL_ERROR
+ }
+ if (!IsPoint(argv[4], aPoint3))
+ {
+ std::cout<<"vtriangle error: the 4th argument must be a point\n";
+ return 1; // TCL_ERROR
+ }
+
+ // Check that points are different
+ Handle(Geom_CartesianPoint) aCartPoint1 =
+ Handle(Geom_CartesianPoint)::DownCast(aPoint1->Component());
+ Handle(Geom_CartesianPoint) aCartPoint2 =
+ Handle(Geom_CartesianPoint)::DownCast(aPoint2->Component());
+ // Test aPoint1 = aPoint2
+ if (IsMatch(aCartPoint1, aCartPoint2))
+ {
+ std::cout<<"vtriangle error: the 1st and the 2nd points are equal\n";
+ return 1; // TCL_ERROR
+ }
+ // Test aPoint2 = aPoint3
+ Handle(Geom_CartesianPoint) aCartPoint3 =
+ Handle(Geom_CartesianPoint)::DownCast(aPoint3->Component());
+ if (IsMatch(aCartPoint2, aCartPoint3))
+ {
+ std::cout<<"vtriangle error: the 2nd and the 3d points are equal\n";
+ return 1; // TCL_ERROR
+ }
+ // Test aPoint3 = aPoint1
+ if (IsMatch(aCartPoint1, aCartPoint3))
+ {
+ std::cout<<"vtriangle error: the 1st and the 3d points are equal\n";
+ return 1; // TCL_ERROR
+ }
+
+ // Create triangle
+ Handle(Triangle) aTriangle = new Triangle(aCartPoint1->Pnt(),
+ aCartPoint2->Pnt(),
+ aCartPoint3->Pnt());
+
+ // Check if there is an object with given name
+ // and remove it from context
+ if (GetMapOfAIS().IsBound2(aName))
+ {
+ Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(aName);
+ Handle(AIS_InteractiveObject) anInterObj =
+ Handle(AIS_InteractiveObject)::DownCast(anObj);
+ TheAISContext()->Remove(anInterObj, Standard_False);
+ GetMapOfAIS().UnBind2(aName);
+ }
+
+ // Bind triangle to its name
+ GetMapOfAIS().Bind(aTriangle, aName);
+
+ // Display triangle
+ TheAISContext()->Display(aTriangle);
+ return 0;
+}
+
+//class : SegmentObject
+//purpose: creates segment based on AIS_InteractiveObject.
+// This class was implemented for testing Select3D_SensitiveCurve
+DEFINE_STANDARD_HANDLE(SegmentObject, AIS_InteractiveObject)
+class SegmentObject: public AIS_InteractiveObject
+{
+public:
+ // CASCADE RTTI
+ DEFINE_STANDARD_RTTI(SegmentObject);
+ SegmentObject (const gp_Pnt& thePnt1, const gp_Pnt& thePnt2);
+protected:
+ void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
+ const Handle(Prs3d_Presentation)& thePresentation,
+ const Standard_Integer theMode);
+
+ void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
+ const Standard_Integer theMode);
+private:
+ gp_Pnt myPoint1;
+ gp_Pnt myPoint2;
+};
+IMPLEMENT_STANDARD_HANDLE(SegmentObject, AIS_InteractiveObject)
+IMPLEMENT_STANDARD_RTTIEXT(SegmentObject, AIS_InteractiveObject)
+
+SegmentObject::SegmentObject (const gp_Pnt& thePnt1, const gp_Pnt& thePnt2)
+{
+ myPoint1 = thePnt1;
+ myPoint2 = thePnt2;
+}
+
+void SegmentObject::Compute (const Handle_PrsMgr_PresentationManager3d &thePresentationManager,
+ const Handle_Prs3d_Presentation &thePresentation,
+ const Standard_Integer theMode)
+{
+ thePresentation->Clear();
+ BRepBuilderAPI_MakeEdge anEdgeMaker(myPoint1, myPoint2);
+ TopoDS_Edge anEdge = anEdgeMaker.Edge();
+ if (anEdge.IsNull())
+ return;
+ BRepAdaptor_Curve aCurveAdaptor(anEdge);
+ StdPrs_Curve::Add(thePresentation, aCurveAdaptor, myDrawer);
+}
+
+void SegmentObject::ComputeSelection (const Handle_SelectMgr_Selection &theSelection,
+ const Standard_Integer theMode)
+{
+ Handle(SelectMgr_EntityOwner) anOwner = new SelectMgr_EntityOwner(this);
+ Handle(TColgp_HArray1OfPnt) anArray = new TColgp_HArray1OfPnt(1, 2);
+ anArray->SetValue(1, myPoint1);
+ anArray->SetValue(2, myPoint2);
+ Handle(Select3D_SensitiveCurve) aSensCurve =
+ new Select3D_SensitiveCurve(anOwner, anArray);
+ theSelection->Add(aSensCurve);
+}
+
+//=======================================================================
+//function : VSegment
+//Draw args : vsegment Name PointName PointName
+//purpose : creates and displays Segment
+//=======================================================================
+static Standard_Integer VSegment (Draw_Interpretor& di,
+ Standard_Integer argc,
+ const char ** argv)
+{
+ // Check arguments
+ if(argc!=4)
+ {
+ std::cout<<"vsegment error: expects 3 arguments\n";
+ return 1; // TCL_ERROR
+ }
+
+ TheAISContext()->CloseAllContexts();
+
+ // Get and check arguments
+ TCollection_AsciiString aName(argv[1]);
+ Handle(AIS_Point) aPoint1, aPoint2;
+ if (!IsPoint(argv[2], aPoint1))
+ {
+ std::cout<<"vsegment error: the 2nd argument should be a point\n";
+ return 1; // TCL_ERROR
+ }
+ if (!IsPoint(argv[3], aPoint2))
+ {
+ std::cout<<"vsegment error: the 3d argument should be a point\n";
+ return 1; // TCL_ERROR
+ }
+ //Check that points are different
+ Handle(Geom_CartesianPoint) aCartPoint1 =
+ Handle(Geom_CartesianPoint)::DownCast(aPoint1->Component());
+ Handle(Geom_CartesianPoint) aCartPoint2 =
+ Handle(Geom_CartesianPoint)::DownCast(aPoint2->Component());
+ if(IsMatch(aCartPoint1, aCartPoint2))
+ {
+ std::cout<<"vsegment error: equal points\n";
+ return 1; // TCL_ERROR
+ }
+
+ // Create segment
+ Handle(SegmentObject) aSegment = new SegmentObject(aCartPoint1->Pnt(), aCartPoint2->Pnt());
+ // Check if there is an object with given name
+ // and remove it from context
+ if (GetMapOfAIS().IsBound2(aName))
+ {
+ Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(aName);
+ Handle(AIS_InteractiveObject) anInterObj =
+ Handle(AIS_InteractiveObject)::DownCast(anObj);
+ TheAISContext()->Remove(anInterObj, Standard_False);
+ GetMapOfAIS().UnBind2(aName);
+ }
+
+ // Bind segment to its name
+ GetMapOfAIS().Bind(aSegment, aName);
+
+ // Display segment
+ TheAISContext()->Display(aSegment);
+ return 0;
+}
+
//=======================================================================
//function : ObjectsCommands
//purpose :
theCommands.Add("vselmode",
"vselmode : [object] mode On/Off (1/0)",
__FILE__, VSetSelectionMode, group);
+
+ theCommands.Add("vtriangle",
+ "vtriangle Name PointName PointName PointName",
+ __FILE__, VTriangle,group);
+
+ theCommands.Add("vsegment",
+ "vsegment Name PointName PointName",
+ __FILE__, VSegment,group);
}