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-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #define BUC60915 //GG 05/06/01 Enable to compute the requested arrow size
18 // if any in all dimensions.
20 #include <AIS_ParallelRelation.ixx>
22 #include <Standard_NotImplemented.hxx>
23 #include <Standard_DomainError.hxx>
25 #include <Precision.hxx>
27 #include <TCollection_AsciiString.hxx>
28 #include <TCollection_ExtendedString.hxx>
30 #include <DsgPrs_LengthPresentation.hxx>
32 #include <Prs3d_Drawer.hxx>
33 #include <Prs3d_ArrowAspect.hxx>
34 #include <Prs3d_DimensionAspect.hxx>
37 #include <AIS_Drawer.hxx>
39 #include <SelectMgr_EntityOwner.hxx>
40 #include <Select3D_SensitiveSegment.hxx>
41 #include <Select3D_SensitiveBox.hxx>
44 #include <TopExp_Explorer.hxx>
45 #include <BRep_Tool.hxx>
46 #include <BRepAdaptor_Surface.hxx>
47 #include <BRepAdaptor_Curve.hxx>
57 #include <gce_MakeLin.hxx>
59 #include <Geom_Plane.hxx>
60 #include <Geom_Line.hxx>
61 #include <Geom_Ellipse.hxx>
63 //=======================================================================
64 //function : Constructor
66 //=======================================================================
67 AIS_ParallelRelation::AIS_ParallelRelation(const TopoDS_Shape& aFShape,
68 const TopoDS_Shape& aSShape,
69 const Handle(Geom_Plane)& aPlane)
74 myAutomaticPosition = Standard_True;
76 mySymbolPrs = DsgPrs_AS_BOTHAR;
79 //=======================================================================
80 //function : Constructor
82 //=======================================================================
83 AIS_ParallelRelation::AIS_ParallelRelation(const TopoDS_Shape& aFShape,
84 const TopoDS_Shape& aSShape,
85 const Handle(Geom_Plane)& aPlane,
86 const gp_Pnt& aPosition,
87 const DsgPrs_ArrowSide aSymbolPrs,
88 const Standard_Real anArrowSize)
93 myAutomaticPosition = Standard_False;
95 SetArrowSize( anArrowSize );
97 myArrowSize = anArrowSize;
99 myPosition = aPosition;
100 mySymbolPrs = aSymbolPrs;
103 //=======================================================================
106 //=======================================================================
107 void AIS_ParallelRelation::Compute(const Handle(PrsMgr_PresentationManager3d)&,
108 const Handle(Prs3d_Presentation)& aPresentation,
109 const Standard_Integer)
111 aPresentation->Clear();
113 switch (myFShape.ShapeType())
117 // cas longueur entre deux faces
118 ComputeTwoFacesParallel(aPresentation);
123 // cas longueur entre deux edges
124 ComputeTwoEdgesParallel(aPresentation);
132 //=======================================================================
134 //purpose : to avoid warning
135 //=======================================================================
136 void AIS_ParallelRelation::Compute(const Handle(Prs3d_Projector)& aProjector,
137 const Handle(Prs3d_Presentation)& aPresentation)
139 // Standard_NotImplemented::Raise("AIS_ParallelRelation::Compute(const Handle(Prs3d_Projector)&,const Handle(Prs3d_Presentation)&)");
140 PrsMgr_PresentableObject::Compute( aProjector , aPresentation ) ;
143 void AIS_ParallelRelation::Compute(const Handle(Prs3d_Projector)& aProjector, const Handle(Geom_Transformation)& aTransformation, const Handle(Prs3d_Presentation)& aPresentation)
145 // Standard_NotImplemented::Raise("AIS_ParallelRelation::Compute(const Handle(Prs3d_Projector)&, const Handle(Geom_Transformation)&, const Handle(Prs3d_Presentation)&)");
146 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
149 //=======================================================================
150 //function : ComputeSelection
152 //=======================================================================
153 void AIS_ParallelRelation::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
154 const Standard_Integer)
156 gp_Lin L1 (myFAttach,myDirAttach);
157 gp_Lin L2 (mySAttach,myDirAttach);
158 gp_Pnt Proj1 = ElCLib::Value(ElCLib::Parameter(L1,myPosition),L1);
159 gp_Pnt Proj2 = ElCLib::Value(ElCLib::Parameter(L2,myPosition),L2);
162 Handle(SelectMgr_EntityOwner) own = new SelectMgr_EntityOwner(this,7);
164 if (!Proj1.IsEqual(Proj2,Precision::Confusion()))
166 L3 = gce_MakeLin(Proj1,Proj2);
170 L3 = gce_MakeLin(Proj1,myDirAttach);
171 Standard_Real size(Min(myVal/100.+1.e-6,myArrowSize+1.e-6));
172 Handle(Select3D_SensitiveBox) box =
173 new Select3D_SensitiveBox(own,
179 myPosition.Z()+size);
180 aSelection->Add(box);
182 Standard_Real parmin,parmax,parcur;
183 parmin = ElCLib::Parameter(L3,Proj1);
186 parcur = ElCLib::Parameter(L3,Proj2);
187 parmin = Min(parmin,parcur);
188 parmax = Max(parmax,parcur);
190 parcur = ElCLib::Parameter(L3,myPosition);
191 parmin = Min(parmin,parcur);
192 parmax = Max(parmax,parcur);
194 gp_Pnt PointMin = ElCLib::Value(parmin,L3);
195 gp_Pnt PointMax = ElCLib::Value(parmax,L3);
197 Handle(Select3D_SensitiveSegment) seg;
199 if (!PointMin.IsEqual(PointMax,Precision::Confusion()))
201 seg = new Select3D_SensitiveSegment(own,
204 aSelection->Add(seg);
206 if (!myFAttach.IsEqual(Proj1,Precision::Confusion()))
208 seg = new Select3D_SensitiveSegment(own, myFAttach, Proj1);
209 aSelection->Add(seg);
211 if (!mySAttach.IsEqual(Proj2,Precision::Confusion()))
213 seg = new Select3D_SensitiveSegment(own, mySAttach, Proj2);
214 aSelection->Add(seg);
218 //=======================================================================
219 //function : ComputeTwoFacesParallel
221 //=======================================================================
222 void AIS_ParallelRelation::ComputeTwoFacesParallel(const Handle(Prs3d_Presentation)&)
224 Standard_NotImplemented::Raise("AIS_ParallelRelation::ComputeTwoFacesParallel not implemented");
227 //=======================================================================
228 //function : ComputeTwoEdgesParallel
230 //=======================================================================
231 void AIS_ParallelRelation::ComputeTwoEdgesParallel(const Handle(Prs3d_Presentation)& aPresentation)
233 TopoDS_Edge E1 = TopoDS::Edge(myFShape);
234 TopoDS_Edge E2 = TopoDS::Edge(mySShape);
236 gp_Pnt ptat11,ptat12,ptat21,ptat22;//,pint3d;
237 Handle(Geom_Curve) geom1,geom2;
238 Standard_Boolean isInfinite1,isInfinite2;
239 Handle(Geom_Curve) extCurv;
240 if (!AIS::ComputeGeometry(E1,E2,myExtShape,
242 ptat11,ptat12,ptat21,ptat22,
244 isInfinite1,isInfinite2,
250 aPresentation->SetInfiniteState((isInfinite1 || isInfinite2) && (myExtShape != 0));
254 Standard_Boolean isEl1 = Standard_False, isEl2 = Standard_False;
256 if (geom1->IsInstance(STANDARD_TYPE(Geom_Ellipse)))
258 const Handle(Geom_Ellipse)& geom_el1 = (Handle(Geom_Ellipse)&) geom1;
259 // construct lines through focuses
260 gp_Ax1 elAx = geom_el1->XAxis();
262 Standard_Real focex = geom_el1->MajorRadius() - geom_el1->Focal()/2.0;
263 gp_Vec transvec = gp_Vec(elAx.Direction())*focex;
264 ptat11 = geom_el1->Focus1().Translated(transvec);
265 ptat12 = geom_el1->Focus2().Translated(-transvec);
266 isEl1 = Standard_True;
268 else if (geom1->IsInstance(STANDARD_TYPE(Geom_Line)))
270 const Handle(Geom_Line)& geom_lin1 = (Handle(Geom_Line)&) geom1;
271 l1 = geom_lin1->Lin();
275 if (geom2->IsInstance(STANDARD_TYPE(Geom_Ellipse)))
277 const Handle(Geom_Ellipse)& geom_el2 = (Handle(Geom_Ellipse)&) geom2;
278 // construct lines through focuses
279 gp_Ax1 elAx = geom_el2->XAxis();
281 Standard_Real focex = geom_el2->MajorRadius() - geom_el2->Focal()/2.0;
282 gp_Vec transvec = gp_Vec(elAx.Direction())*focex;
283 ptat21 = geom_el2->Focus1().Translated(transvec);
284 ptat22 = geom_el2->Focus2().Translated(-transvec);
285 isEl2 = Standard_True;
287 else if (geom2->IsInstance(STANDARD_TYPE(Geom_Line)))
289 const Handle(Geom_Line)& geom_lin2 = (Handle(Geom_Line)&) geom2;
290 l2 = geom_lin2->Lin();
294 const Handle(Geom_Line)& geom_lin1 = new Geom_Line(l1);
295 const Handle(Geom_Line)& geom_lin2 = new Geom_Line(l2);
297 myDirAttach = l1.Direction();
300 if( !myArrowSizeIsDefined ) {
302 Standard_Real arrSize1 (myArrowSize), arrSize2 (myArrowSize);
303 if (!isInfinite1) arrSize1 = ptat11.Distance(ptat12)/50.;
304 if (!isInfinite2) arrSize2 = ptat21.Distance(ptat22)/50.;
305 myArrowSize = Max(myArrowSize,Max(arrSize1,arrSize2));
306 // myArrowSize = Min(myArrowSize,Min(arrSize1,arrSize2));
311 if ( myAutomaticPosition )
316 gp_Pnt p2 = ElCLib::Value(ElCLib::Parameter(l2,ptat11),l2);
317 curpos.SetXYZ((ptat11.XYZ() + p2.XYZ())/2.);
319 else if ( !isInfinite2 )
321 gp_Pnt p2 = ElCLib::Value(ElCLib::Parameter(l1,ptat21),l1);
322 curpos.SetXYZ((ptat21.XYZ()+p2.XYZ())/2.);
326 curpos.SetXYZ((l1.Location().XYZ()+l2.Location().XYZ())/2.);
328 // offset pour eviter confusion Edge et Dimension
329 gp_Vec offset (myDirAttach);
330 offset = offset*myArrowSize*(-10.);
331 curpos.Translate(offset);
335 // recherche points attache
340 if (myPosition.Distance(ptat11) < myPosition.Distance(ptat12)) myFAttach = ptat12;
341 else myFAttach = ptat11;
345 if (myPosition.Distance(ptat11) > myPosition.Distance(ptat12)) myFAttach = ptat12;
346 else myFAttach = ptat11;
351 myFAttach = ElCLib::Value(ElCLib::Parameter(l1,myPosition),l1);
358 if (myPosition.Distance(ptat21) < myPosition.Distance(ptat22)) mySAttach = ptat22;
359 else mySAttach = ptat21;
363 if (myPosition.Distance(ptat21) > myPosition.Distance(ptat22)) mySAttach = ptat22;
364 else mySAttach = ptat21;
369 mySAttach = ElCLib::Value(ElCLib::Parameter(l2,myPosition),l2);
371 TCollection_ExtendedString aText (" //");
373 if (l1.Distance(l2) <= Precision::Confusion())
377 Handle(Prs3d_DimensionAspect) la = myDrawer->DimensionAspect();
378 Handle(Prs3d_ArrowAspect) arr = la->ArrowAspect();
379 arr->SetLength(myArrowSize);
380 arr = la->ArrowAspect();
381 arr->SetLength(myArrowSize);
382 if ( myExtShape == 1)
383 mySymbolPrs = DsgPrs_AS_FIRSTPT_LASTAR;
384 else if ( myExtShape == 2)
385 mySymbolPrs = DsgPrs_AS_FIRSTAR_LASTPT;
387 DsgPrs_LengthPresentation::Add(aPresentation,
395 if ( (myExtShape != 0) && !extCurv.IsNull())
398 if ( myExtShape == 1 )
405 ComputeProjEdgePresentation(aPresentation,E1,geom_lin1,pf,pl);
414 ComputeProjEdgePresentation(aPresentation,E2,geom_lin2,pf,pl);