1 // Created on: 1996-12-05
2 // Created by: Jean-Pierre COMBE/Odile Olivier
3 // Copyright (c) 1996-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.
22 #define BUC60915 //GG 05/06/01 Enable to compute the requested arrow size
23 // if any in all dimensions.
25 #include <AIS_ParallelRelation.ixx>
27 #include <Standard_NotImplemented.hxx>
28 #include <Standard_DomainError.hxx>
30 #include <Precision.hxx>
32 #include <TCollection_AsciiString.hxx>
33 #include <TCollection_ExtendedString.hxx>
35 #include <DsgPrs_LengthPresentation.hxx>
37 #include <Prs3d_Drawer.hxx>
38 #include <Prs3d_ArrowAspect.hxx>
39 #include <Prs3d_LengthAspect.hxx>
42 #include <AIS_Drawer.hxx>
44 #include <SelectMgr_EntityOwner.hxx>
45 #include <Select3D_SensitiveSegment.hxx>
46 #include <Select3D_SensitiveBox.hxx>
49 #include <TopExp_Explorer.hxx>
50 #include <BRep_Tool.hxx>
51 #include <BRepAdaptor_Surface.hxx>
52 #include <BRepAdaptor_Curve.hxx>
62 #include <gce_MakeLin.hxx>
64 #include <Geom_Plane.hxx>
65 #include <Geom_Line.hxx>
66 #include <Geom_Ellipse.hxx>
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)
79 myAutomaticPosition = Standard_True;
81 mySymbolPrs = DsgPrs_AS_BOTHAR;
84 //=======================================================================
85 //function : Constructor
87 //=======================================================================
88 AIS_ParallelRelation::AIS_ParallelRelation(const TopoDS_Shape& aFShape,
89 const TopoDS_Shape& aSShape,
90 const Handle(Geom_Plane)& aPlane,
91 const gp_Pnt& aPosition,
92 const DsgPrs_ArrowSide aSymbolPrs,
93 const Standard_Real anArrowSize)
98 myAutomaticPosition = Standard_False;
100 SetArrowSize( anArrowSize );
102 myArrowSize = anArrowSize;
104 myPosition = aPosition;
105 mySymbolPrs = aSymbolPrs;
108 //=======================================================================
111 //=======================================================================
112 void AIS_ParallelRelation::Compute(const Handle(PrsMgr_PresentationManager3d)&,
113 const Handle(Prs3d_Presentation)& aPresentation,
114 const Standard_Integer)
116 aPresentation->Clear();
118 switch (myFShape.ShapeType())
122 // cas longueur entre deux faces
123 ComputeTwoFacesParallel(aPresentation);
128 // cas longueur entre deux edges
129 ComputeTwoEdgesParallel(aPresentation);
137 //=======================================================================
139 //purpose : to avoid warning
140 //=======================================================================
141 void AIS_ParallelRelation::Compute(const Handle(Prs3d_Projector)& aProjector,
142 const Handle(Prs3d_Presentation)& aPresentation)
144 // Standard_NotImplemented::Raise("AIS_ParallelRelation::Compute(const Handle(Prs3d_Projector)&,const Handle(Prs3d_Presentation)&)");
145 PrsMgr_PresentableObject::Compute( aProjector , aPresentation ) ;
148 //=======================================================================
150 //purpose : to avoid warning
151 //=======================================================================
152 void AIS_ParallelRelation::Compute(const Handle(PrsMgr_PresentationManager2d)& aPresentationManager2d,
153 const Handle(Graphic2d_GraphicObject)& aGraphicObject,
154 const Standard_Integer anInteger)
156 // Standard_NotImplemented::Raise("AIS_ParallelRelation::Compute(const Handle(PrsMgr_PresentationManager2d)&,const Handle(Graphic2d_GraphicObject)&,const Standard_Integer)");
157 PrsMgr_PresentableObject::Compute( aPresentationManager2d ,aGraphicObject,anInteger) ;
160 void AIS_ParallelRelation::Compute(const Handle_Prs3d_Projector& aProjector, const Handle_Geom_Transformation& aTransformation, const Handle_Prs3d_Presentation& aPresentation)
162 // Standard_NotImplemented::Raise("AIS_ParallelRelation::Compute(const Handle_Prs3d_Projector&, const Handle_Geom_Transformation&, const Handle_Prs3d_Presentation&)");
163 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
166 //=======================================================================
167 //function : ComputeSelection
169 //=======================================================================
170 void AIS_ParallelRelation::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
171 const Standard_Integer)
173 gp_Lin L1 (myFAttach,myDirAttach);
174 gp_Lin L2 (mySAttach,myDirAttach);
175 gp_Pnt Proj1 = ElCLib::Value(ElCLib::Parameter(L1,myPosition),L1);
176 gp_Pnt Proj2 = ElCLib::Value(ElCLib::Parameter(L2,myPosition),L2);
179 Handle(SelectMgr_EntityOwner) own = new SelectMgr_EntityOwner(this,7);
181 if (!Proj1.IsEqual(Proj2,Precision::Confusion()))
183 L3 = gce_MakeLin(Proj1,Proj2);
187 L3 = gce_MakeLin(Proj1,myDirAttach);
188 Standard_Real size(Min(myVal/100.+1.e-6,myArrowSize+1.e-6));
189 Handle(Select3D_SensitiveBox) box =
190 new Select3D_SensitiveBox(own,
196 myPosition.Z()+size);
197 aSelection->Add(box);
199 Standard_Real parmin,parmax,parcur;
200 parmin = ElCLib::Parameter(L3,Proj1);
203 parcur = ElCLib::Parameter(L3,Proj2);
204 parmin = Min(parmin,parcur);
205 parmax = Max(parmax,parcur);
207 parcur = ElCLib::Parameter(L3,myPosition);
208 parmin = Min(parmin,parcur);
209 parmax = Max(parmax,parcur);
211 gp_Pnt PointMin = ElCLib::Value(parmin,L3);
212 gp_Pnt PointMax = ElCLib::Value(parmax,L3);
214 Handle(Select3D_SensitiveSegment) seg;
216 if (!PointMin.IsEqual(PointMax,Precision::Confusion()))
218 seg = new Select3D_SensitiveSegment(own,
221 aSelection->Add(seg);
223 if (!myFAttach.IsEqual(Proj1,Precision::Confusion()))
225 seg = new Select3D_SensitiveSegment(own, myFAttach, Proj1);
226 aSelection->Add(seg);
228 if (!mySAttach.IsEqual(Proj2,Precision::Confusion()))
230 seg = new Select3D_SensitiveSegment(own, mySAttach, Proj2);
231 aSelection->Add(seg);
235 //=======================================================================
236 //function : ComputeTwoFacesParallel
238 //=======================================================================
239 void AIS_ParallelRelation::ComputeTwoFacesParallel(const Handle(Prs3d_Presentation)&)
241 Standard_NotImplemented::Raise("AIS_ParallelRelation::ComputeTwoFacesParallel not implemented");
244 //=======================================================================
245 //function : ComputeTwoEdgesParallel
247 //=======================================================================
248 void AIS_ParallelRelation::ComputeTwoEdgesParallel(const Handle(Prs3d_Presentation)& aPresentation)
250 TopoDS_Edge E1 = TopoDS::Edge(myFShape);
251 TopoDS_Edge E2 = TopoDS::Edge(mySShape);
253 gp_Pnt ptat11,ptat12,ptat21,ptat22;//,pint3d;
254 Handle(Geom_Curve) geom1,geom2;
255 Standard_Boolean isInfinite1,isInfinite2;
256 Handle(Geom_Curve) extCurv;
257 if (!AIS::ComputeGeometry(E1,E2,myExtShape,
259 ptat11,ptat12,ptat21,ptat22,
261 isInfinite1,isInfinite2,
267 aPresentation->SetInfiniteState((isInfinite1 || isInfinite2) && (myExtShape != 0));
271 Standard_Boolean isEl1 = Standard_False, isEl2 = Standard_False;
273 if (geom1->IsInstance(STANDARD_TYPE(Geom_Ellipse)))
275 const Handle(Geom_Ellipse)& geom_el1 = (Handle(Geom_Ellipse)&) geom1;
276 // construct lines through focuses
277 gp_Ax1 elAx = geom_el1->XAxis();
279 Standard_Real focex = geom_el1->MajorRadius() - geom_el1->Focal()/2.0;
280 gp_Vec transvec = gp_Vec(elAx.Direction())*focex;
281 ptat11 = geom_el1->Focus1().Translated(transvec);
282 ptat12 = geom_el1->Focus2().Translated(-transvec);
283 isEl1 = Standard_True;
285 else if (geom1->IsInstance(STANDARD_TYPE(Geom_Line)))
287 const Handle(Geom_Line)& geom_lin1 = (Handle(Geom_Line)&) geom1;
288 l1 = geom_lin1->Lin();
292 if (geom2->IsInstance(STANDARD_TYPE(Geom_Ellipse)))
294 const Handle(Geom_Ellipse)& geom_el2 = (Handle(Geom_Ellipse)&) geom2;
295 // construct lines through focuses
296 gp_Ax1 elAx = geom_el2->XAxis();
298 Standard_Real focex = geom_el2->MajorRadius() - geom_el2->Focal()/2.0;
299 gp_Vec transvec = gp_Vec(elAx.Direction())*focex;
300 ptat21 = geom_el2->Focus1().Translated(transvec);
301 ptat22 = geom_el2->Focus2().Translated(-transvec);
302 isEl2 = Standard_True;
304 else if (geom2->IsInstance(STANDARD_TYPE(Geom_Line)))
306 const Handle(Geom_Line)& geom_lin2 = (Handle(Geom_Line)&) geom2;
307 l2 = geom_lin2->Lin();
311 const Handle(Geom_Line)& geom_lin1 = new Geom_Line(l1);
312 const Handle(Geom_Line)& geom_lin2 = new Geom_Line(l2);
314 myDirAttach = l1.Direction();
317 if( !myArrowSizeIsDefined ) {
319 Standard_Real arrSize1 (myArrowSize), arrSize2 (myArrowSize);
320 if (!isInfinite1) arrSize1 = ptat11.Distance(ptat12)/50.;
321 if (!isInfinite2) arrSize2 = ptat21.Distance(ptat22)/50.;
322 myArrowSize = Max(myArrowSize,Max(arrSize1,arrSize2));
323 // myArrowSize = Min(myArrowSize,Min(arrSize1,arrSize2));
328 if ( myAutomaticPosition )
333 gp_Pnt p2 = ElCLib::Value(ElCLib::Parameter(l2,ptat11),l2);
334 curpos.SetXYZ((ptat11.XYZ() + p2.XYZ())/2.);
336 else if ( !isInfinite2 )
338 gp_Pnt p2 = ElCLib::Value(ElCLib::Parameter(l1,ptat21),l1);
339 curpos.SetXYZ((ptat21.XYZ()+p2.XYZ())/2.);
343 curpos.SetXYZ((l1.Location().XYZ()+l2.Location().XYZ())/2.);
345 // offset pour eviter confusion Edge et Dimension
346 gp_Vec offset (myDirAttach);
347 offset = offset*myArrowSize*(-10.);
348 curpos.Translate(offset);
352 // recherche points attache
357 if (myPosition.Distance(ptat11) < myPosition.Distance(ptat12)) myFAttach = ptat12;
358 else myFAttach = ptat11;
362 if (myPosition.Distance(ptat11) > myPosition.Distance(ptat12)) myFAttach = ptat12;
363 else myFAttach = ptat11;
368 myFAttach = ElCLib::Value(ElCLib::Parameter(l1,myPosition),l1);
375 if (myPosition.Distance(ptat21) < myPosition.Distance(ptat22)) mySAttach = ptat22;
376 else mySAttach = ptat21;
380 if (myPosition.Distance(ptat21) > myPosition.Distance(ptat22)) mySAttach = ptat22;
381 else mySAttach = ptat21;
386 mySAttach = ElCLib::Value(ElCLib::Parameter(l2,myPosition),l2);
388 TCollection_ExtendedString aText (" //");
390 if (l1.Distance(l2) <= Precision::Confusion())
394 Handle(Prs3d_LengthAspect) la = myDrawer->LengthAspect();
395 Handle(Prs3d_ArrowAspect) arr = la->Arrow1Aspect();
396 arr->SetLength(myArrowSize);
397 arr = la->Arrow2Aspect();
398 arr->SetLength(myArrowSize);
399 if ( myExtShape == 1)
400 mySymbolPrs = DsgPrs_AS_FIRSTPT_LASTAR;
401 else if ( myExtShape == 2)
402 mySymbolPrs = DsgPrs_AS_FIRSTAR_LASTPT;
404 DsgPrs_LengthPresentation::Add(aPresentation,
412 if ( (myExtShape != 0) && !extCurv.IsNull())
415 if ( myExtShape == 1 )
422 ComputeProjEdgePresentation(aPresentation,E1,geom_lin1,pf,pl);
431 ComputeProjEdgePresentation(aPresentation,E2,geom_lin2,pf,pl);