Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 1998-01-20 |
2 | // Created by: Julia GERASIMOVA | |
3 | // Copyright (c) 1998-1999 Matra Datavision | |
973c2be1 | 4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e | 5 | // |
973c2be1 | 6 | // This file is part of Open CASCADE Technology software library. |
b311480e | 7 | // |
d5f74e42 | 8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published | |
973c2be1 | 10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT | |
12 | // distribution for complete text of the license and disclaimer of any warranty. | |
b311480e | 13 | // |
973c2be1 | 14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. | |
7fd59977 | 16 | |
7fd59977 | 17 | |
18 | #include <AIS.hxx> | |
42cf5bc1 | 19 | #include <AIS_EqualRadiusRelation.hxx> |
7fd59977 | 20 | #include <BRepAdaptor_Curve.hxx> |
42cf5bc1 | 21 | #include <DsgPrs_EqualRadiusPresentation.hxx> |
7fd59977 | 22 | #include <ElCLib.hxx> |
42cf5bc1 | 23 | #include <Geom_Circle.hxx> |
24 | #include <Geom_Plane.hxx> | |
25 | #include <Geom_Transformation.hxx> | |
7fd59977 | 26 | #include <GeomAPI_ProjectPointOnSurf.hxx> |
42cf5bc1 | 27 | #include <gp_Circ.hxx> |
28 | #include <Precision.hxx> | |
7fd59977 | 29 | #include <Prs3d_ArrowAspect.hxx> |
42cf5bc1 | 30 | #include <Prs3d_DimensionAspect.hxx> |
6262338c | 31 | #include <Prs3d_Drawer.hxx> |
42cf5bc1 | 32 | #include <Prs3d_Presentation.hxx> |
33 | #include <Prs3d_Projector.hxx> | |
34 | #include <Select3D_SensitiveBox.hxx> | |
35 | #include <Select3D_SensitiveSegment.hxx> | |
36 | #include <SelectMgr_EntityOwner.hxx> | |
37 | #include <SelectMgr_Selection.hxx> | |
38 | #include <Standard_NotImplemented.hxx> | |
39 | #include <Standard_Type.hxx> | |
40 | #include <TopoDS.hxx> | |
41 | #include <TopoDS_Edge.hxx> | |
7fd59977 | 42 | |
92efcf78 | 43 | IMPLEMENT_STANDARD_RTTIEXT(AIS_EqualRadiusRelation,AIS_Relation) |
44 | ||
7fd59977 | 45 | //======================================================================= |
46 | //function : AIS_EqualRadiusRelation | |
47 | //purpose : | |
48 | //======================================================================= | |
7fd59977 | 49 | AIS_EqualRadiusRelation::AIS_EqualRadiusRelation( const TopoDS_Edge& aFirstEdge, |
50 | const TopoDS_Edge& aSecondEdge, | |
51 | const Handle( Geom_Plane )& aPlane ) | |
52 | :AIS_Relation() | |
53 | { | |
54 | myFShape = aFirstEdge; | |
55 | mySShape = aSecondEdge; | |
56 | myPlane = aPlane; | |
57 | } | |
58 | ||
59 | //======================================================================= | |
60 | //function : Compute | |
61 | //purpose : | |
62 | //======================================================================= | |
63 | ||
64 | void AIS_EqualRadiusRelation::Compute( const Handle( PrsMgr_PresentationManager3d )&, | |
65 | const Handle( Prs3d_Presentation )& aPresentation, | |
66 | const Standard_Integer ) | |
67 | { | |
7fd59977 | 68 | BRepAdaptor_Curve FirstCurve( TopoDS::Edge( myFShape ) ), SecondCurve( TopoDS::Edge( mySShape ) ); |
69 | ||
70 | Standard_Real FirstPar1 = FirstCurve.FirstParameter(), LastPar1 = FirstCurve.LastParameter(), | |
71 | FirstPar2 = SecondCurve.FirstParameter(), LastPar2 = SecondCurve.LastParameter(); | |
72 | ||
73 | Handle( Geom_Curve ) FirstProjCurve = FirstCurve.Curve().Curve(), | |
74 | SecondProjCurve = SecondCurve.Curve().Curve(); | |
75 | gp_Pnt FirstPoint1, LastPoint1, FirstPoint2, LastPoint2; | |
76 | Standard_Boolean isFirstOnPlane, isSecondOnPlane; | |
77 | ||
78 | AIS::ComputeGeomCurve( FirstProjCurve, FirstPar1, LastPar1, FirstPoint1, LastPoint1, myPlane, isFirstOnPlane ); | |
79 | AIS::ComputeGeomCurve( SecondProjCurve, FirstPar2, LastPar2, FirstPoint2, LastPoint2, myPlane, isSecondOnPlane ); | |
80 | ||
81 | if (!isFirstOnPlane) | |
82 | ComputeProjEdgePresentation( aPresentation, TopoDS::Edge( myFShape ), FirstProjCurve, FirstPoint1, LastPoint1 ); | |
83 | if (! isSecondOnPlane) | |
84 | ComputeProjEdgePresentation( aPresentation, TopoDS::Edge( mySShape ), SecondProjCurve, FirstPoint2, LastPoint2 ); | |
85 | ||
86 | gp_Circ FirstCirc = (Handle( Geom_Circle )::DownCast( FirstProjCurve ))->Circ(); | |
87 | gp_Circ SecondCirc = (Handle( Geom_Circle )::DownCast( SecondProjCurve ))->Circ(); | |
88 | ||
89 | myFirstCenter = FirstCirc.Location(); | |
90 | mySecondCenter = SecondCirc.Location(); | |
91 | ||
92 | //ota -- begin -- | |
93 | if (myAutomaticPosition) | |
94 | { | |
95 | myFirstPoint = ElCLib::Value( (FirstPar1 + LastPar1)*0.5, FirstCirc ); | |
96 | mySecondPoint = ElCLib::Value( (FirstPar2 + LastPar2)*0.5, SecondCirc ); | |
97 | } | |
98 | else { | |
99 | Standard_Real aPar = ElCLib::Parameter(FirstCirc, myFirstPoint); | |
c6541a0c D |
100 | if (IntegerPart(0.5*LastPar1/M_PI) != 0 && aPar < FirstPar1 ) |
101 | aPar +=2*M_PI*IntegerPart(0.5*LastPar1/M_PI); | |
7fd59977 | 102 | Standard_Real aRadius = FirstCirc.Radius(); |
103 | ||
104 | if (Abs(myFirstPoint.Distance(myFirstCenter) - aRadius) >= Precision::Confusion()) | |
105 | myFirstPoint = ElCLib::Value(aPar, FirstCirc); | |
106 | if ( FirstPoint1.Distance(LastPoint1) > Precision::Confusion()){ | |
107 | //check where is myFirstPoint | |
108 | if (aPar > LastPar1 || aPar < FirstPar1) | |
109 | { | |
110 | //myFirstPoint is out of Arc of FirstCircle | |
111 | if (FirstPoint1.Distance(myFirstPoint)< LastPoint1.Distance(myFirstPoint)) | |
112 | myFirstPoint = FirstPoint1; | |
113 | else | |
114 | myFirstPoint = LastPoint1; | |
115 | } | |
116 | } | |
117 | ||
118 | ||
119 | aPar = ElCLib::Parameter(SecondCirc, mySecondPoint); | |
c6541a0c D |
120 | if (IntegerPart(0.5*LastPar2/M_PI) != 0 && aPar < FirstPar2 ) |
121 | aPar +=2*M_PI*IntegerPart(0.5*LastPar2/M_PI); | |
7fd59977 | 122 | |
123 | aRadius = SecondCirc.Radius(); | |
124 | if (Abs(mySecondPoint.Distance(mySecondCenter) - aRadius) >= Precision::Confusion()) | |
125 | mySecondPoint = ElCLib::Value(aPar, SecondCirc); | |
126 | if (FirstPoint2.Distance(LastPoint2) > Precision::Confusion()){ | |
127 | if (aPar > LastPar2 || aPar < FirstPar2) | |
128 | { //mySecondPoint is out of Arc of mySecondCircle | |
129 | if (FirstPoint2.Distance(mySecondPoint)< LastPoint2.Distance(mySecondPoint)) | |
130 | mySecondPoint = FirstPoint2; | |
131 | else | |
132 | mySecondPoint = LastPoint2; | |
133 | } | |
134 | } | |
135 | } | |
7fd59977 | 136 | if( !myArrowSizeIsDefined ) |
7fd59977 | 137 | myArrowSize = (Min(myFirstCenter.Distance(myFirstPoint), |
138 | mySecondCenter.Distance(mySecondPoint)))*0.05; | |
139 | ||
a6eb515f | 140 | Handle(Prs3d_DimensionAspect) la = myDrawer->DimensionAspect(); |
141 | Handle(Prs3d_ArrowAspect) arr = la->ArrowAspect(); | |
7fd59977 | 142 | arr->SetLength(myArrowSize); |
143 | ||
144 | //ota -- end -- | |
145 | ||
146 | DsgPrs_EqualRadiusPresentation::Add(aPresentation, myDrawer, | |
147 | myFirstCenter, mySecondCenter, myFirstPoint, mySecondPoint, myPlane ); | |
148 | } | |
149 | ||
150 | //======================================================================= | |
151 | //function : Compute | |
152 | //purpose : to avoid warning at compilation (SUN) | |
153 | //======================================================================= | |
154 | ||
155 | void AIS_EqualRadiusRelation::Compute( const Handle( Prs3d_Projector )& /*aProjector*/, | |
156 | const Handle( Prs3d_Presentation )& /*aPresentation*/) | |
157 | { | |
158 | // Standard_NotImplemented::Raise("AIS_EqualRadiusRelation::Compute( const Handle( Prs3d_Projector )&,const Handle( Prs3d_Presentation )& )"); | |
159 | // PrsMgr_PresentableObject::Compute( aProjector , aPresentation ) ; | |
160 | } | |
161 | ||
7fd59977 | 162 | //======================================================================= |
163 | //function : Compute | |
164 | //purpose : | |
165 | //======================================================================= | |
166 | ||
857ffd5e | 167 | void AIS_EqualRadiusRelation::Compute(const Handle(Prs3d_Projector)& aProjector, |
168 | const Handle(Geom_Transformation)& aTransformation, | |
169 | const Handle(Prs3d_Presentation)& aPresentation) | |
7fd59977 | 170 | { |
857ffd5e | 171 | // Standard_NotImplemented::Raise("AIS_EqualRadiusRelation::Compute(const Handle(Prs3d_Projector)&, const Handle(Geom_Transformation)&, const Handle(Prs3d_Presentation)&)"); |
7fd59977 | 172 | PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ; |
173 | } | |
174 | ||
175 | //======================================================================= | |
176 | //function : ComputeSelection | |
177 | //purpose : | |
178 | //======================================================================= | |
179 | ||
180 | void AIS_EqualRadiusRelation::ComputeSelection( const Handle( SelectMgr_Selection )& aSelection, | |
181 | const Standard_Integer ) | |
182 | { | |
183 | Handle( SelectMgr_EntityOwner ) own = new SelectMgr_EntityOwner( this, 7 ); | |
184 | Handle( Select3D_SensitiveSegment ) seg; | |
185 | ||
186 | seg = new Select3D_SensitiveSegment( own, myFirstCenter, myFirstPoint ); | |
187 | aSelection->Add( seg ); | |
188 | ||
189 | if(!myAutomaticPosition) | |
190 | ComputeRadiusPosition(); | |
191 | ||
192 | seg = new Select3D_SensitiveSegment( own, mySecondCenter, mySecondPoint ); | |
193 | aSelection->Add( seg ); | |
194 | ||
195 | seg = new Select3D_SensitiveSegment( own, myFirstCenter, mySecondCenter ); | |
196 | aSelection->Add( seg ); | |
197 | ||
198 | ||
199 | // Two small lines | |
200 | gp_Pnt Middle( (myFirstCenter.XYZ() + mySecondCenter.XYZ())*0.5 ); | |
201 | ||
202 | Standard_Real SmallDist = .001; | |
203 | //Should be changed as the domain of small lines could be changed. | |
204 | Handle( Select3D_SensitiveBox ) box = new Select3D_SensitiveBox(own, | |
205 | Middle.X() - SmallDist, | |
206 | Middle.Y() - SmallDist, | |
207 | Middle.Z() - SmallDist, | |
208 | Middle.X() + SmallDist, | |
209 | Middle.Y() + SmallDist, | |
210 | Middle.Z() + SmallDist ); | |
211 | aSelection->Add(box); | |
212 | } | |
213 | ||
214 | //================================================================= | |
215 | //function : ComputeRadiusPosition | |
216 | //purpose : | |
217 | //================================================================= | |
218 | void AIS_EqualRadiusRelation::ComputeRadiusPosition() | |
219 | { | |
220 | if (myAutomaticPosition || | |
221 | myFirstCenter.Distance(myPosition) < Precision::Confusion() || | |
222 | mySecondCenter.Distance(myPosition) < Precision::Confusion()) | |
223 | return; | |
224 | ||
225 | gp_Pnt aPosition; | |
226 | ||
227 | //project myPosition to the plane of constraint | |
228 | GeomAPI_ProjectPointOnSurf aProj(myPosition, myPlane); | |
229 | aPosition = aProj.NearestPoint(); | |
230 | ||
231 | Standard_Real aDist1 = myFirstPoint.Distance(aPosition); | |
232 | Standard_Real aDist2 = mySecondPoint.Distance(aPosition); | |
233 | ||
234 | if(aDist1<aDist2) | |
235 | { | |
236 | Standard_Real Rad1 = myFirstPoint.Distance(myFirstCenter); | |
237 | const gp_Dir aNewDir1(aPosition.XYZ() - myFirstCenter.XYZ()); | |
238 | const gp_Vec aTVec (aNewDir1.XYZ()*Rad1); | |
239 | myFirstPoint = myFirstCenter.Translated(aTVec); | |
240 | } | |
241 | else { | |
242 | Standard_Real Rad2 = mySecondPoint.Distance(mySecondCenter); | |
243 | const gp_Dir aNewDir2(aPosition.XYZ() - mySecondCenter.XYZ()); | |
244 | gp_Vec aTVec (aNewDir2.XYZ()*Rad2); | |
245 | mySecondPoint = mySecondCenter.Translated(aTVec); | |
246 | } | |
247 | ||
248 | } | |
249 |