1 // File: AIS_ParallelRelation.cdl
2 // Created: Tue Dec 5 15:09:04 1996
3 // Author: Jean-Pierre COMBE/Odile Olivier
6 #define BUC60915 //GG 05/06/01 Enable to compute the requested arrow size
7 // if any in all dimensions.
9 #include <AIS_ParallelRelation.ixx>
11 #include <Standard_NotImplemented.hxx>
12 #include <Standard_DomainError.hxx>
14 #include <Precision.hxx>
16 #include <TCollection_AsciiString.hxx>
17 #include <TCollection_ExtendedString.hxx>
19 #include <DsgPrs_LengthPresentation.hxx>
21 #include <Prs3d_Drawer.hxx>
22 #include <Prs3d_ArrowAspect.hxx>
23 #include <Prs3d_LengthAspect.hxx>
26 #include <AIS_Drawer.hxx>
28 #include <SelectMgr_EntityOwner.hxx>
29 #include <Select3D_SensitiveSegment.hxx>
30 #include <Select3D_SensitiveBox.hxx>
33 #include <TopExp_Explorer.hxx>
34 #include <BRep_Tool.hxx>
35 #include <BRepAdaptor_Surface.hxx>
36 #include <BRepAdaptor_Curve.hxx>
46 #include <gce_MakeLin.hxx>
48 #include <Geom_Plane.hxx>
49 #include <Geom_Line.hxx>
50 #include <Geom_Ellipse.hxx>
52 //=======================================================================
53 //function : Constructor
55 //=======================================================================
56 AIS_ParallelRelation::AIS_ParallelRelation(const TopoDS_Shape& aFShape,
57 const TopoDS_Shape& aSShape,
58 const Handle(Geom_Plane)& aPlane)
63 myAutomaticPosition = Standard_True;
65 mySymbolPrs = DsgPrs_AS_BOTHAR;
68 //=======================================================================
69 //function : Constructor
71 //=======================================================================
72 AIS_ParallelRelation::AIS_ParallelRelation(const TopoDS_Shape& aFShape,
73 const TopoDS_Shape& aSShape,
74 const Handle(Geom_Plane)& aPlane,
75 const gp_Pnt& aPosition,
76 const DsgPrs_ArrowSide aSymbolPrs,
77 const Standard_Real anArrowSize)
82 myAutomaticPosition = Standard_False;
84 SetArrowSize( anArrowSize );
86 myArrowSize = anArrowSize;
88 myPosition = aPosition;
89 mySymbolPrs = aSymbolPrs;
92 //=======================================================================
95 //=======================================================================
96 void AIS_ParallelRelation::Compute(const Handle(PrsMgr_PresentationManager3d)&,
97 const Handle(Prs3d_Presentation)& aPresentation,
98 const Standard_Integer)
100 aPresentation->Clear();
102 switch (myFShape.ShapeType())
106 // cas longueur entre deux faces
107 ComputeTwoFacesParallel(aPresentation);
112 // cas longueur entre deux edges
113 ComputeTwoEdgesParallel(aPresentation);
121 //=======================================================================
123 //purpose : to avoid warning
124 //=======================================================================
125 void AIS_ParallelRelation::Compute(const Handle(Prs3d_Projector)& aProjector,
126 const Handle(Prs3d_Presentation)& aPresentation)
128 // Standard_NotImplemented::Raise("AIS_ParallelRelation::Compute(const Handle(Prs3d_Projector)&,const Handle(Prs3d_Presentation)&)");
129 PrsMgr_PresentableObject::Compute( aProjector , aPresentation ) ;
132 //=======================================================================
134 //purpose : to avoid warning
135 //=======================================================================
136 void AIS_ParallelRelation::Compute(const Handle(PrsMgr_PresentationManager2d)& aPresentationManager2d,
137 const Handle(Graphic2d_GraphicObject)& aGraphicObject,
138 const Standard_Integer anInteger)
140 // Standard_NotImplemented::Raise("AIS_ParallelRelation::Compute(const Handle(PrsMgr_PresentationManager2d)&,const Handle(Graphic2d_GraphicObject)&,const Standard_Integer)");
141 PrsMgr_PresentableObject::Compute( aPresentationManager2d ,aGraphicObject,anInteger) ;
144 void AIS_ParallelRelation::Compute(const Handle_Prs3d_Projector& aProjector, const Handle_Geom_Transformation& aTransformation, const Handle_Prs3d_Presentation& aPresentation)
146 // Standard_NotImplemented::Raise("AIS_ParallelRelation::Compute(const Handle_Prs3d_Projector&, const Handle_Geom_Transformation&, const Handle_Prs3d_Presentation&)");
147 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
150 //=======================================================================
151 //function : ComputeSelection
153 //=======================================================================
154 void AIS_ParallelRelation::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
155 const Standard_Integer)
157 gp_Lin L1 (myFAttach,myDirAttach);
158 gp_Lin L2 (mySAttach,myDirAttach);
159 gp_Pnt Proj1 = ElCLib::Value(ElCLib::Parameter(L1,myPosition),L1);
160 gp_Pnt Proj2 = ElCLib::Value(ElCLib::Parameter(L2,myPosition),L2);
163 Handle(SelectMgr_EntityOwner) own = new SelectMgr_EntityOwner(this,7);
165 if (!Proj1.IsEqual(Proj2,Precision::Confusion()))
167 L3 = gce_MakeLin(Proj1,Proj2);
171 L3 = gce_MakeLin(Proj1,myDirAttach);
172 Standard_Real size(Min(myVal/100.+1.e-6,myArrowSize+1.e-6));
173 Handle(Select3D_SensitiveBox) box =
174 new Select3D_SensitiveBox(own,
180 myPosition.Z()+size);
181 aSelection->Add(box);
183 Standard_Real parmin,parmax,parcur;
184 parmin = ElCLib::Parameter(L3,Proj1);
187 parcur = ElCLib::Parameter(L3,Proj2);
188 parmin = Min(parmin,parcur);
189 parmax = Max(parmax,parcur);
191 parcur = ElCLib::Parameter(L3,myPosition);
192 parmin = Min(parmin,parcur);
193 parmax = Max(parmax,parcur);
195 gp_Pnt PointMin = ElCLib::Value(parmin,L3);
196 gp_Pnt PointMax = ElCLib::Value(parmax,L3);
198 Handle(Select3D_SensitiveSegment) seg;
200 if (!PointMin.IsEqual(PointMax,Precision::Confusion()))
202 seg = new Select3D_SensitiveSegment(own,
205 aSelection->Add(seg);
207 if (!myFAttach.IsEqual(Proj1,Precision::Confusion()))
209 seg = new Select3D_SensitiveSegment(own, myFAttach, Proj1);
210 aSelection->Add(seg);
212 if (!mySAttach.IsEqual(Proj2,Precision::Confusion()))
214 seg = new Select3D_SensitiveSegment(own, mySAttach, Proj2);
215 aSelection->Add(seg);
219 //=======================================================================
220 //function : ComputeTwoFacesParallel
222 //=======================================================================
223 void AIS_ParallelRelation::ComputeTwoFacesParallel(const Handle(Prs3d_Presentation)&)
225 Standard_NotImplemented::Raise("AIS_ParallelRelation::ComputeTwoFacesParallel not implemented");
228 //=======================================================================
229 //function : ComputeTwoEdgesParallel
231 //=======================================================================
232 void AIS_ParallelRelation::ComputeTwoEdgesParallel(const Handle(Prs3d_Presentation)& aPresentation)
234 TopoDS_Edge E1 = TopoDS::Edge(myFShape);
235 TopoDS_Edge E2 = TopoDS::Edge(mySShape);
237 gp_Pnt ptat11,ptat12,ptat21,ptat22;//,pint3d;
238 Handle(Geom_Curve) geom1,geom2;
239 Standard_Boolean isInfinite1,isInfinite2;
240 Handle(Geom_Curve) extCurv;
241 if (!AIS::ComputeGeometry(E1,E2,myExtShape,
243 ptat11,ptat12,ptat21,ptat22,
245 isInfinite1,isInfinite2,
251 aPresentation->SetInfiniteState((isInfinite1 || isInfinite2) && (myExtShape != 0));
255 Standard_Boolean isEl1 = Standard_False, isEl2 = Standard_False;
257 if (geom1->IsInstance(STANDARD_TYPE(Geom_Ellipse)))
259 const Handle(Geom_Ellipse)& geom_el1 = (Handle(Geom_Ellipse)&) geom1;
260 // construct lines through focuses
261 gp_Ax1 elAx = geom_el1->XAxis();
263 Standard_Real focex = geom_el1->MajorRadius() - geom_el1->Focal()/2.0;
264 gp_Vec transvec = gp_Vec(elAx.Direction())*focex;
265 ptat11 = geom_el1->Focus1().Translated(transvec);
266 ptat12 = geom_el1->Focus2().Translated(-transvec);
267 isEl1 = Standard_True;
269 else if (geom1->IsInstance(STANDARD_TYPE(Geom_Line)))
271 const Handle(Geom_Line)& geom_lin1 = (Handle(Geom_Line)&) geom1;
272 l1 = geom_lin1->Lin();
276 if (geom2->IsInstance(STANDARD_TYPE(Geom_Ellipse)))
278 const Handle(Geom_Ellipse)& geom_el2 = (Handle(Geom_Ellipse)&) geom2;
279 // construct lines through focuses
280 gp_Ax1 elAx = geom_el2->XAxis();
282 Standard_Real focex = geom_el2->MajorRadius() - geom_el2->Focal()/2.0;
283 gp_Vec transvec = gp_Vec(elAx.Direction())*focex;
284 ptat21 = geom_el2->Focus1().Translated(transvec);
285 ptat22 = geom_el2->Focus2().Translated(-transvec);
286 isEl2 = Standard_True;
288 else if (geom2->IsInstance(STANDARD_TYPE(Geom_Line)))
290 const Handle(Geom_Line)& geom_lin2 = (Handle(Geom_Line)&) geom2;
291 l2 = geom_lin2->Lin();
295 const Handle(Geom_Line)& geom_lin1 = new Geom_Line(l1);
296 const Handle(Geom_Line)& geom_lin2 = new Geom_Line(l2);
298 myDirAttach = l1.Direction();
301 if( !myArrowSizeIsDefined ) {
303 Standard_Real arrSize1 (myArrowSize), arrSize2 (myArrowSize);
304 if (!isInfinite1) arrSize1 = ptat11.Distance(ptat12)/50.;
305 if (!isInfinite2) arrSize2 = ptat21.Distance(ptat22)/50.;
306 myArrowSize = Max(myArrowSize,Max(arrSize1,arrSize2));
307 // myArrowSize = Min(myArrowSize,Min(arrSize1,arrSize2));
312 if ( myAutomaticPosition )
317 gp_Pnt p2 = ElCLib::Value(ElCLib::Parameter(l2,ptat11),l2);
318 curpos.SetXYZ((ptat11.XYZ() + p2.XYZ())/2.);
320 else if ( !isInfinite2 )
322 gp_Pnt p2 = ElCLib::Value(ElCLib::Parameter(l1,ptat21),l1);
323 curpos.SetXYZ((ptat21.XYZ()+p2.XYZ())/2.);
327 curpos.SetXYZ((l1.Location().XYZ()+l2.Location().XYZ())/2.);
329 // offset pour eviter confusion Edge et Dimension
330 gp_Vec offset (myDirAttach);
331 offset = offset*myArrowSize*(-10.);
332 curpos.Translate(offset);
336 // recherche points attache
341 if (myPosition.Distance(ptat11) < myPosition.Distance(ptat12)) myFAttach = ptat12;
342 else myFAttach = ptat11;
346 if (myPosition.Distance(ptat11) > myPosition.Distance(ptat12)) myFAttach = ptat12;
347 else myFAttach = ptat11;
352 myFAttach = ElCLib::Value(ElCLib::Parameter(l1,myPosition),l1);
359 if (myPosition.Distance(ptat21) < myPosition.Distance(ptat22)) mySAttach = ptat22;
360 else mySAttach = ptat21;
364 if (myPosition.Distance(ptat21) > myPosition.Distance(ptat22)) mySAttach = ptat22;
365 else mySAttach = ptat21;
370 mySAttach = ElCLib::Value(ElCLib::Parameter(l2,myPosition),l2);
372 TCollection_ExtendedString aText (" //");
374 if (l1.Distance(l2) <= Precision::Confusion())
378 Handle(Prs3d_LengthAspect) la = myDrawer->LengthAspect();
379 Handle(Prs3d_ArrowAspect) arr = la->Arrow1Aspect();
380 arr->SetLength(myArrowSize);
381 arr = la->Arrow2Aspect();
382 arr->SetLength(myArrowSize);
383 if ( myExtShape == 1)
384 mySymbolPrs = DsgPrs_AS_FIRSTPT_LASTAR;
385 else if ( myExtShape == 2)
386 mySymbolPrs = DsgPrs_AS_FIRSTAR_LASTPT;
388 DsgPrs_LengthPresentation::Add(aPresentation,
396 if ( (myExtShape != 0) && !extCurv.IsNull())
399 if ( myExtShape == 1 )
406 ComputeProjEdgePresentation(aPresentation,E1,geom_lin1,pf,pl);
415 ComputeProjEdgePresentation(aPresentation,E2,geom_lin2,pf,pl);