1 // Created on: 1998-01-27
2 // Created by: Julia GERASIMOVA
3 // Copyright (c) 1998-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.
19 #include <DsgPrs_EqualDistancePresentation.hxx>
21 #include <gce_MakeDir.hxx>
22 #include <Geom_Plane.hxx>
23 #include <gp_Circ.hxx>
28 #include <Graphic3d_ArrayOfPolylines.hxx>
29 #include <Graphic3d_ArrayOfSegments.hxx>
30 #include <Graphic3d_Group.hxx>
31 #include <Precision.hxx>
32 #include <Prs3d_DimensionAspect.hxx>
33 #include <Prs3d_LineAspect.hxx>
34 #include <Prs3d_Presentation.hxx>
35 #include <Prs3d_Text.hxx>
36 #include <TCollection_ExtendedString.hxx>
38 //=================================================================================
40 //=================================================================================
41 void DsgPrs_EqualDistancePresentation::Add( const Handle( Prs3d_Presentation )& aPresentation,
42 const Handle( Prs3d_Drawer )& aDrawer,
47 const Handle( Geom_Plane )& Plane )
49 Handle( Prs3d_DimensionAspect ) LA = aDrawer->DimensionAspect();
50 aPresentation->CurrentGroup()->SetPrimitivesAspect( LA->LineAspect()->Aspect() );
52 // Line between two middles
53 gp_Pnt Middle12( (Point1.XYZ() + Point2.XYZ()) * 0.5 ), Middle34( (Point3.XYZ() + Point4.XYZ()) * 0.5 );
55 Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(2);
56 aPrims->AddVertex(Middle12);
57 aPrims->AddVertex(Middle34);
58 aPresentation->CurrentGroup()->AddPrimitiveArray(aPrims);
60 // Add presentation of arrows (points)
61 gp_Dir aDir( 0, 0, 1 );
62 DsgPrs::ComputeSymbol(aPresentation, LA, Middle12, Middle34, aDir, aDir, DsgPrs_AS_BOTHPT );
64 // Two small lines in the middle of this line
65 gp_Pnt Middle( (Middle12.XYZ() + Middle34.XYZ()) * 0.5 ), aTextPos;
66 Standard_Real Dist = Middle12.Distance( Middle34 );
67 Standard_Real SmallDist;
68 gp_Dir LineDir, OrtDir;
69 gp_Vec LineVec, OrtVec;
71 if (Dist > Precision::Confusion())
73 SmallDist = Dist * 0.05; // 1/20.0 part
74 if (SmallDist <= Precision::Confusion())
76 LineDir = gce_MakeDir( Middle12, Middle34 );
77 OrtDir = Plane->Pln().Axis().Direction() ^ LineDir;
78 LineVec = gp_Vec( LineDir ) * SmallDist;
79 OrtVec = gp_Vec( OrtDir ) * SmallDist;
81 aTextPos = Middle.Translated( OrtVec );
85 gp_Vec Vec1( Middle, Point1 );
87 if (Vec1.SquareMagnitude() > Precision::Confusion()*Precision::Confusion())
89 Standard_Real Angle = gp_Vec( Middle, Point1 ).Angle( gp_Vec( Middle, Point3 ) );
90 gp_Pnt MidPnt = Point1.Rotated( Plane->Pln().Axis(), Angle*0.5 );
91 OrtDir = gce_MakeDir( Middle, MidPnt );
92 LineDir = OrtDir ^ Plane->Pln().Axis().Direction();
94 Standard_Real Distance = Point1.Distance( Point2 );
95 SmallDist = Distance * 0.05; // 1/20.0
96 if (SmallDist <= Precision::Confusion())
99 OrtVec = gp_Vec( OrtDir ) * SmallDist;
100 LineVec = gp_Vec( LineDir ) * SmallDist;
105 OrtVec = gp_Vec( Plane->Pln().XAxis().Direction() ) * SmallDist;
106 LineVec = gp_Vec( Plane->Pln().YAxis().Direction() ) * SmallDist;
108 aTextPos = Middle.Translated (OrtVec);
111 TCollection_ExtendedString aText("==");
114 Prs3d_Text::Draw (aPresentation->CurrentGroup(),LA->TextAspect(), aText, aTextPos);
118 //==================================================================================
119 //function : AddInterval
120 //purpose : is used for presentation of interval between two lines or two points,
121 // or between one line and one point.
122 //==================================================================================
123 void DsgPrs_EqualDistancePresentation::AddInterval(const Handle(Prs3d_Presentation)& aPresentation,
124 const Handle(Prs3d_Drawer)& aDrawer,
125 const gp_Pnt& aPoint1,
126 const gp_Pnt& aPoint2,
127 const gp_Dir& aDirection,
128 const gp_Pnt& aPosition,
129 const DsgPrs_ArrowSide anArrowSide,
133 const Handle(Prs3d_DimensionAspect) LA = aDrawer->DimensionAspect();
134 aPresentation->CurrentGroup()->SetPrimitivesAspect(LA->LineAspect()->Aspect());
136 gp_Lin L1 (aPoint1,aDirection);
137 gp_Lin L2 (aPoint2,aDirection);
138 aProj1 = ElCLib::Value(ElCLib::Parameter(L1, aPosition),L1);
139 aProj2 = ElCLib::Value(ElCLib::Parameter(L2, aPosition),L2);
141 Handle(Graphic3d_ArrayOfPolylines) aPrims = new Graphic3d_ArrayOfPolylines(4);
142 aPrims->AddVertex(aPoint1);
143 aPrims->AddVertex(aProj1);
144 aPrims->AddVertex(aProj2);
145 aPrims->AddVertex(aPoint2);
146 aPresentation->CurrentGroup()->AddPrimitiveArray(aPrims);
148 //add arrows presentation
149 gp_Dir aDir(aProj2.XYZ() - aProj1.XYZ());
151 DsgPrs::ComputeSymbol(aPresentation, LA, aProj1, aProj2, aDir.Reversed(), aDir, anArrowSide);
155 //========================================================================
156 // function : AddIntervalBetweenTwoArcs
157 // purpose : is used for presentation of interval between two arcs. One
158 // of the arcs can have a zero radius (being a point really)
159 //========================================================================
161 DsgPrs_EqualDistancePresentation::AddIntervalBetweenTwoArcs(const Handle(Prs3d_Presentation)& aPresentation,
162 const Handle(Prs3d_Drawer)& aDrawer,
163 const gp_Circ& aCirc1,
164 const gp_Circ& aCirc2,
165 const gp_Pnt& aPoint1,
166 const gp_Pnt& aPoint2,
167 const gp_Pnt& aPoint3,
168 const gp_Pnt& aPoint4,
169 const DsgPrs_ArrowSide anArrowSide)
171 const Handle(Prs3d_DimensionAspect) LA = aDrawer->DimensionAspect();
172 aPresentation->CurrentGroup()->SetPrimitivesAspect(LA->LineAspect()->Aspect());
174 Standard_Real aPar11, aPar12, aPar21, aPar22;
175 if(aCirc1.Radius() > Precision::Confusion()){
176 aPar11 = ElCLib::Parameter (aCirc1, aPoint1);
177 aPar12 = ElCLib::Parameter(aCirc1, aPoint2);
183 if (aCirc2.Radius() > Precision::Confusion()){
184 aPar21 = ElCLib::Parameter(aCirc2, aPoint3 );
185 aPar22 = ElCLib::Parameter(aCirc2, aPoint4);
192 Handle(Graphic3d_ArrayOfPrimitives) aPrims = new Graphic3d_ArrayOfSegments(2);
193 aPrims->AddVertex(aPoint2);
194 aPrims->AddVertex(aPoint4);
195 aPresentation->CurrentGroup()->AddPrimitiveArray(aPrims);
197 Standard_Integer i, aNodeNb;
198 Standard_Real aDelta, aCurPar;
199 if(aPar12 < aPar11 ) aPar12 += 2.*M_PI;
200 if (Abs(aPar12 - aPar11) > Precision::Confusion())
202 aNodeNb = Standard_Integer(Max(Abs(aPar12 - aPar11)*50./M_PI + 0.5, 4.));
203 aDelta = (aPar12 - aPar11)/aNodeNb;
206 aPrims = new Graphic3d_ArrayOfPolylines(aNodeNb+1);
207 for (i = 1; i<= aNodeNb; aCurPar += aDelta, i++)
208 aPrims->AddVertex(ElCLib::Value( aCurPar, aCirc1));
209 aPrims->AddVertex(aPoint2);
210 aPresentation->CurrentGroup()->AddPrimitiveArray(aPrims);
212 if (aPar22 < aPar21) aPar22 += 2.*M_PI;
213 if ( Abs(aPar22 - aPar21) > Precision::Confusion())
215 aNodeNb = Standard_Integer(Max(Abs(aPar22 - aPar21)*50./M_PI + 0.5, 4.));
216 aDelta = (aPar22 - aPar21)/aNodeNb;
219 aPrims = new Graphic3d_ArrayOfPolylines(aNodeNb+1);
220 for (i = 1; i<= aNodeNb; aCurPar += aDelta, i++)
221 aPrims->AddVertex(ElCLib::Value( aCurPar, aCirc2));
222 aPrims->AddVertex(aPoint4);
223 aPresentation->CurrentGroup()->AddPrimitiveArray(aPrims);
226 //get the direction of interval
228 if(aPoint4.Distance(aPoint2) > Precision::Confusion())
230 DirOfArrow.SetXYZ(aPoint4.XYZ() - aPoint2.XYZ());
234 //Let's take the radius direction
235 gp_Pnt aCenter = aCirc1.Location();
236 if(aPoint4.Distance(aCenter) < Precision::Confusion())
238 DirOfArrow.SetXYZ(aPoint4.XYZ() - aCenter.XYZ());
241 // Add presentation of arrows
242 DsgPrs::ComputeSymbol( aPresentation, LA, aPoint2, aPoint4, DirOfArrow.Reversed(), DirOfArrow, anArrowSide );