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 #include <PrsDim_ParallelRelation.hxx>
20 #include <BRep_Tool.hxx>
21 #include <BRepAdaptor_Curve.hxx>
22 #include <BRepAdaptor_Surface.hxx>
23 #include <DsgPrs_LengthPresentation.hxx>
25 #include <gce_MakeLin.hxx>
26 #include <Geom_Ellipse.hxx>
27 #include <Geom_Line.hxx>
28 #include <Geom_Plane.hxx>
35 #include <Precision.hxx>
36 #include <Prs3d_ArrowAspect.hxx>
37 #include <Prs3d_DimensionAspect.hxx>
38 #include <Prs3d_Drawer.hxx>
39 #include <Prs3d_Presentation.hxx>
40 #include <Select3D_SensitiveBox.hxx>
41 #include <Select3D_SensitiveSegment.hxx>
42 #include <SelectMgr_EntityOwner.hxx>
43 #include <SelectMgr_Selection.hxx>
44 #include <Standard_DomainError.hxx>
45 #include <Standard_NotImplemented.hxx>
46 #include <TCollection_AsciiString.hxx>
47 #include <TCollection_ExtendedString.hxx>
49 #include <TopoDS_Shape.hxx>
51 IMPLEMENT_STANDARD_RTTIEXT(PrsDim_ParallelRelation, PrsDim_Relation)
53 //=======================================================================
54 //function : Constructor
56 //=======================================================================
57 PrsDim_ParallelRelation::PrsDim_ParallelRelation(const TopoDS_Shape& aFShape,
58 const TopoDS_Shape& aSShape,
59 const Handle(Geom_Plane)& aPlane)
64 myAutomaticPosition = Standard_True;
66 mySymbolPrs = DsgPrs_AS_BOTHAR;
69 //=======================================================================
70 //function : Constructor
72 //=======================================================================
73 PrsDim_ParallelRelation::PrsDim_ParallelRelation(const TopoDS_Shape& aFShape,
74 const TopoDS_Shape& aSShape,
75 const Handle(Geom_Plane)& aPlane,
76 const gp_Pnt& aPosition,
77 const DsgPrs_ArrowSide aSymbolPrs,
78 const Standard_Real anArrowSize)
83 myAutomaticPosition = Standard_False;
84 SetArrowSize( anArrowSize );
85 myPosition = aPosition;
86 mySymbolPrs = aSymbolPrs;
89 //=======================================================================
92 //=======================================================================
93 void PrsDim_ParallelRelation::Compute(const Handle(PrsMgr_PresentationManager3d)&,
94 const Handle(Prs3d_Presentation)& aPresentation,
95 const Standard_Integer)
97 switch (myFShape.ShapeType())
101 // cas longueur entre deux faces
102 ComputeTwoFacesParallel(aPresentation);
107 // cas longueur entre deux edges
108 ComputeTwoEdgesParallel(aPresentation);
116 //=======================================================================
117 //function : ComputeSelection
119 //=======================================================================
120 void PrsDim_ParallelRelation::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
121 const Standard_Integer)
123 gp_Lin L1 (myFAttach,myDirAttach);
124 gp_Lin L2 (mySAttach,myDirAttach);
125 gp_Pnt Proj1 = ElCLib::Value(ElCLib::Parameter(L1,myPosition),L1);
126 gp_Pnt Proj2 = ElCLib::Value(ElCLib::Parameter(L2,myPosition),L2);
129 Handle(SelectMgr_EntityOwner) own = new SelectMgr_EntityOwner(this,7);
131 if (!Proj1.IsEqual(Proj2,Precision::Confusion()))
133 L3 = gce_MakeLin(Proj1,Proj2);
137 L3 = gce_MakeLin(Proj1,myDirAttach);
138 Standard_Real size(Min(myVal/100.+1.e-6,myArrowSize+1.e-6));
139 Handle(Select3D_SensitiveBox) box =
140 new Select3D_SensitiveBox(own,
146 myPosition.Z()+size);
147 aSelection->Add(box);
149 Standard_Real parmin,parmax,parcur;
150 parmin = ElCLib::Parameter(L3,Proj1);
153 parcur = ElCLib::Parameter(L3,Proj2);
154 parmin = Min(parmin,parcur);
155 parmax = Max(parmax,parcur);
157 parcur = ElCLib::Parameter(L3,myPosition);
158 parmin = Min(parmin,parcur);
159 parmax = Max(parmax,parcur);
161 gp_Pnt PointMin = ElCLib::Value(parmin,L3);
162 gp_Pnt PointMax = ElCLib::Value(parmax,L3);
164 Handle(Select3D_SensitiveSegment) seg;
166 if (!PointMin.IsEqual(PointMax,Precision::Confusion()))
168 seg = new Select3D_SensitiveSegment(own,
171 aSelection->Add(seg);
173 if (!myFAttach.IsEqual(Proj1,Precision::Confusion()))
175 seg = new Select3D_SensitiveSegment(own, myFAttach, Proj1);
176 aSelection->Add(seg);
178 if (!mySAttach.IsEqual(Proj2,Precision::Confusion()))
180 seg = new Select3D_SensitiveSegment(own, mySAttach, Proj2);
181 aSelection->Add(seg);
185 //=======================================================================
186 //function : ComputeTwoFacesParallel
188 //=======================================================================
189 void PrsDim_ParallelRelation::ComputeTwoFacesParallel(const Handle(Prs3d_Presentation)&)
191 throw Standard_NotImplemented("PrsDim_ParallelRelation::ComputeTwoFacesParallel not implemented");
194 //=======================================================================
195 //function : ComputeTwoEdgesParallel
197 //=======================================================================
198 void PrsDim_ParallelRelation::ComputeTwoEdgesParallel(const Handle(Prs3d_Presentation)& aPresentation)
200 TopoDS_Edge E1 = TopoDS::Edge(myFShape);
201 TopoDS_Edge E2 = TopoDS::Edge(mySShape);
203 gp_Pnt ptat11,ptat12,ptat21,ptat22;//,pint3d;
204 Handle(Geom_Curve) geom1,geom2;
205 Standard_Boolean isInfinite1,isInfinite2;
206 Handle(Geom_Curve) extCurv;
207 if (!PrsDim::ComputeGeometry(E1,E2,myExtShape,
209 ptat11,ptat12,ptat21,ptat22,
211 isInfinite1,isInfinite2,
217 aPresentation->SetInfiniteState((isInfinite1 || isInfinite2) && (myExtShape != 0));
221 Standard_Boolean isEl1 = Standard_False, isEl2 = Standard_False;
223 if (geom1->IsInstance(STANDARD_TYPE(Geom_Ellipse)))
225 Handle(Geom_Ellipse) geom_el1 (Handle(Geom_Ellipse)::DownCast (geom1));
226 // construct lines through focuses
227 gp_Ax1 elAx = geom_el1->XAxis();
229 Standard_Real focex = geom_el1->MajorRadius() - geom_el1->Focal()/2.0;
230 gp_Vec transvec = gp_Vec(elAx.Direction())*focex;
231 ptat11 = geom_el1->Focus1().Translated(transvec);
232 ptat12 = geom_el1->Focus2().Translated(-transvec);
233 isEl1 = Standard_True;
235 else if (geom1->IsInstance(STANDARD_TYPE(Geom_Line)))
237 Handle(Geom_Line) geom_lin1 (Handle(Geom_Line)::DownCast (geom1));
238 l1 = geom_lin1->Lin();
242 if (geom2->IsInstance(STANDARD_TYPE(Geom_Ellipse)))
244 Handle(Geom_Ellipse) geom_el2 (Handle(Geom_Ellipse)::DownCast (geom2));
245 // construct lines through focuses
246 gp_Ax1 elAx = geom_el2->XAxis();
248 Standard_Real focex = geom_el2->MajorRadius() - geom_el2->Focal()/2.0;
249 gp_Vec transvec = gp_Vec(elAx.Direction())*focex;
250 ptat21 = geom_el2->Focus1().Translated(transvec);
251 ptat22 = geom_el2->Focus2().Translated(-transvec);
252 isEl2 = Standard_True;
254 else if (geom2->IsInstance(STANDARD_TYPE(Geom_Line)))
256 Handle(Geom_Line) geom_lin2 (Handle(Geom_Line)::DownCast (geom2));
257 l2 = geom_lin2->Lin();
261 const Handle(Geom_Line)& geom_lin1 = new Geom_Line(l1);
262 const Handle(Geom_Line)& geom_lin2 = new Geom_Line(l2);
264 myDirAttach = l1.Direction();
266 if( !myArrowSizeIsDefined ) {
267 Standard_Real arrSize1 (myArrowSize), arrSize2 (myArrowSize);
268 if (!isInfinite1) arrSize1 = ptat11.Distance(ptat12)/50.;
269 if (!isInfinite2) arrSize2 = ptat21.Distance(ptat22)/50.;
270 myArrowSize = Max(myArrowSize,Max(arrSize1,arrSize2));
271 // myArrowSize = Min(myArrowSize,Min(arrSize1,arrSize2));
274 if ( myAutomaticPosition )
279 gp_Pnt p2 = ElCLib::Value(ElCLib::Parameter(l2,ptat11),l2);
280 curpos.SetXYZ((ptat11.XYZ() + p2.XYZ())/2.);
282 else if ( !isInfinite2 )
284 gp_Pnt p2 = ElCLib::Value(ElCLib::Parameter(l1,ptat21),l1);
285 curpos.SetXYZ((ptat21.XYZ()+p2.XYZ())/2.);
289 curpos.SetXYZ((l1.Location().XYZ()+l2.Location().XYZ())/2.);
291 // offset pour eviter confusion Edge et Dimension
292 gp_Vec offset (myDirAttach);
293 offset = offset*myArrowSize*(-10.);
294 curpos.Translate(offset);
298 // recherche points attache
303 if (myPosition.Distance(ptat11) < myPosition.Distance(ptat12)) myFAttach = ptat12;
304 else myFAttach = ptat11;
308 if (myPosition.Distance(ptat11) > myPosition.Distance(ptat12)) myFAttach = ptat12;
309 else myFAttach = ptat11;
314 myFAttach = ElCLib::Value(ElCLib::Parameter(l1,myPosition),l1);
321 if (myPosition.Distance(ptat21) < myPosition.Distance(ptat22)) mySAttach = ptat22;
322 else mySAttach = ptat21;
326 if (myPosition.Distance(ptat21) > myPosition.Distance(ptat22)) mySAttach = ptat22;
327 else mySAttach = ptat21;
332 mySAttach = ElCLib::Value(ElCLib::Parameter(l2,myPosition),l2);
334 TCollection_ExtendedString aText (" //");
336 if (l1.Distance(l2) <= Precision::Confusion())
340 Handle(Prs3d_DimensionAspect) la = myDrawer->DimensionAspect();
341 Handle(Prs3d_ArrowAspect) arr = la->ArrowAspect();
342 arr->SetLength(myArrowSize);
343 arr = la->ArrowAspect();
344 arr->SetLength(myArrowSize);
345 if ( myExtShape == 1)
346 mySymbolPrs = DsgPrs_AS_FIRSTPT_LASTAR;
347 else if ( myExtShape == 2)
348 mySymbolPrs = DsgPrs_AS_FIRSTAR_LASTPT;
350 DsgPrs_LengthPresentation::Add(aPresentation,
358 if ( (myExtShape != 0) && !extCurv.IsNull())
361 if ( myExtShape == 1 )
368 ComputeProjEdgePresentation(aPresentation,E1,geom_lin1,pf,pl);
377 ComputeProjEdgePresentation(aPresentation,E2,geom_lin2,pf,pl);