1 // Created on: 1995-03-13
2 // Created by: Robert COUBLANC
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
24 #include <Select3D_SensitiveCurve.ixx>
25 #include <SelectBasics_BasicTool.hxx>
26 #include <gp_Lin2d.hxx>
27 #include <Precision.hxx>
29 #include <CSLib_Class2d.hxx>
32 //==================================================
35 //==================================================
37 Select3D_SensitiveCurve
38 ::Select3D_SensitiveCurve(const Handle(SelectBasics_EntityOwner)& OwnerId,
39 const Handle(Geom_Curve)& C,
40 const Standard_Integer NbPoints):
41 Select3D_SensitivePoly(OwnerId, NbPoints),
45 LoadPoints(C,NbPoints);
48 //==================================================
51 //==================================================
53 Select3D_SensitiveCurve
54 ::Select3D_SensitiveCurve(const Handle(SelectBasics_EntityOwner)& OwnerId,
55 const Handle(TColgp_HArray1OfPnt)& ThePoints):
56 Select3D_SensitivePoly(OwnerId, ThePoints),
61 //==================================================
64 //==================================================
66 Select3D_SensitiveCurve
67 ::Select3D_SensitiveCurve(const Handle(SelectBasics_EntityOwner)& OwnerId,
68 const TColgp_Array1OfPnt& ThePoints):
69 Select3D_SensitivePoly(OwnerId, ThePoints),
74 //==================================================
77 //==================================================
79 Standard_Boolean Select3D_SensitiveCurve::Matches (const SelectBasics_PickArgs& thePickArgs,
80 Standard_Real& theMatchDMin,
81 Standard_Real& theMatchDepth)
83 Standard_Integer Rank;
84 TColgp_Array1OfPnt2d aArrayOf2dPnt(1, mypolyg.Size());
85 Points2D(aArrayOf2dPnt);
86 if (SelectBasics_BasicTool::MatchPolyg2d (aArrayOf2dPnt,
87 thePickArgs.X(), thePickArgs.Y(),
88 thePickArgs.Tolerance(),
92 // remember detected segment (for GetLastDetected)
95 theMatchDepth = ComputeDepth (thePickArgs.PickLine(), Rank);
97 return !thePickArgs.IsClipped (theMatchDepth);
100 return Standard_False;
103 //==================================================
105 // Purpose : know if a box touches the projected polygon
107 //==================================================
109 Standard_Boolean Select3D_SensitiveCurve::
110 Matches (const Standard_Real XMin,
111 const Standard_Real YMin,
112 const Standard_Real XMax,
113 const Standard_Real YMax,
114 const Standard_Real aTol)
117 BoundBox.Update(XMin-aTol,YMin-aTol,XMax+aTol,YMax+aTol);
119 for(Standard_Integer anIndex=0; anIndex<mypolyg.Size(); ++anIndex)
121 if(BoundBox.IsOut(mypolyg.Pnt2d(anIndex)))
122 return Standard_False;
124 return Standard_True;
127 //=======================================================================
130 //=======================================================================
132 Standard_Boolean Select3D_SensitiveCurve::
133 Matches (const TColgp_Array1OfPnt2d& aPoly,
134 const Bnd_Box2d& aBox,
135 const Standard_Real aTol)
137 Standard_Real Umin,Vmin,Umax,Vmax;
138 aBox.Get(Umin,Vmin,Umax,Vmax);
139 CSLib_Class2d aClassifier2d(aPoly,aTol,aTol,Umin,Vmin,Umax,Vmax);
141 for(Standard_Integer anIndex=0;anIndex<mypolyg.Size();++anIndex)
143 Standard_Integer RES = aClassifier2d.SiDans(mypolyg.Pnt2d(anIndex));
145 return Standard_False;
147 return Standard_True;
150 //==================================================
151 // Function: LoadPoints
153 //==================================================
155 void Select3D_SensitiveCurve
156 ::LoadPoints (const Handle(Geom_Curve)& aCurve,const Standard_Integer NbP)
158 /*this method is private and it used only inside of constructor.
159 That's why check !NbP==mypolyg3d->Length() was removed*/
161 Standard_Real Step = (aCurve->LastParameter()- aCurve->FirstParameter())/(NbP-1);
162 Standard_Real Curparam = aCurve->FirstParameter();
163 for(Standard_Integer anIndex=0;anIndex<mypolyg.Size();++anIndex)
165 mypolyg.SetPnt(anIndex, aCurve->Value(Curparam));
170 //=======================================================================
173 //=======================================================================
175 void Select3D_SensitiveCurve::Dump(Standard_OStream& S,const Standard_Boolean FullDump) const
177 S<<"\tSensitiveCurve 3D :"<<endl;
179 S<<"\t\tExisting Location"<<endl;
181 S<<"\t\tNumber Of Points :"<<mypolyg.Size()<<endl;
185 Select3D_SensitiveEntity::DumpBox(S,mybox2d);
189 //=======================================================================
190 //function : ComputeDepth
192 //=======================================================================
194 Standard_Real Select3D_SensitiveCurve::ComputeDepth (const gp_Lin& thePickLine,
195 const Standard_Integer theSegment) const
199 return Precision::Infinite();
202 // In case if theSegment and theSegment + 1 are not valid
203 // the depth will be infinite
204 if (theSegment >= mypolyg.Size())
206 return Precision::Infinite();
209 gp_XYZ aCDG = mypolyg.Pnt (theSegment);
211 if (theSegment + 1 < mypolyg.Size())
213 aCDG += mypolyg.Pnt(theSegment + 1);
217 return ElCLib::Parameter (thePickLine, gp_Pnt (aCDG));
220 //=======================================================================
221 //function : GetConnected
223 //=======================================================================
225 Handle(Select3D_SensitiveEntity) Select3D_SensitiveCurve::GetConnected(const TopLoc_Location &theLocation)
227 // Create a copy of this
228 Handle(Select3D_SensitiveEntity) aNewEntity;
229 // this was constructed using Handle(Geom_Curve)
230 if (!myCurve.IsNull())
232 aNewEntity = new Select3D_SensitiveCurve(myOwnerId, myCurve);
234 // this was constructed using TColgp_HArray1OfPnt
237 Standard_Integer aSize = mypolyg.Size();
238 Handle(TColgp_HArray1OfPnt) aPoints = new TColgp_HArray1OfPnt(1, aSize);
239 // Fill the array with points from mypolyg3d
240 for (Standard_Integer anIndex = 1; anIndex <= aSize; ++anIndex)
242 aPoints->SetValue(anIndex, mypolyg.Pnt(anIndex-1));
244 aNewEntity = new Select3D_SensitiveCurve(myOwnerId, aPoints);
248 aNewEntity->SetLocation(Location());
250 aNewEntity->UpdateLocation(theLocation);