0024239: Eliminate GCC compiler warning (multi-line comment)
[occt.git] / src / DsgPrs / DsgPrs_EllipseRadiusPresentation.cxx
CommitLineData
b311480e 1// Created on: 1998-01-26
2// Created by: Sergey ZARITCHNY
3// Copyright (c) 1998-1999 Matra Datavision
4// Copyright (c) 1999-2012 OPEN CASCADE SAS
5//
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.
10//
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.
13//
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.
20
7fd59977 21#include <DsgPrs_EllipseRadiusPresentation.ixx>
22
23#include <gp_Lin.hxx>
24#include <gp_Dir.hxx>
25#include <gp_Elips.hxx>
26#include <ElCLib.hxx>
27#include <Graphic3d_Group.hxx>
b8ddfc2f 28#include <Graphic3d_ArrayOfSegments.hxx>
29#include <Graphic3d_ArrayOfPolylines.hxx>
7fd59977 30#include <Prs3d_LengthAspect.hxx>
31#include <Prs3d_Arrow.hxx>
32#include <Prs3d_ArrowAspect.hxx>
33#include <Prs3d_LineAspect.hxx>
34#include <Prs3d_Text.hxx>
35#include <TCollection_AsciiString.hxx>
36#include <TCollection_ExtendedString.hxx>
37
38#include <Graphic3d_Vertex.hxx>
39#include <Graphic3d_AspectMarker3d.hxx>
40#include <Graphic3d_AspectLine3d.hxx>
41#include <Aspect_TypeOfLine.hxx>
42#include <Aspect_TypeOfMarker.hxx>
43#include <Aspect_AspectMarker.hxx>
44#include <Quantity_Color.hxx>
45#include <DsgPrs.hxx>
46#include <Precision.hxx>
47
48#include <Geom_Ellipse.hxx>
49#include <Geom_Line.hxx>
50#include <Geom_TrimmedCurve.hxx>
51#include <GeomAPI_ExtremaCurveCurve.hxx>
52#include <Geom_OffsetCurve.hxx>
b8ddfc2f 53
7fd59977 54//=======================================================================
55//function : Add
56//purpose :
57//=======================================================================
58
59void DsgPrs_EllipseRadiusPresentation::Add (const Handle(Prs3d_Presentation)& aPresentation,
60 const Handle(Prs3d_Drawer)& aDrawer,
61 const Standard_Real theval,
62 const TCollection_ExtendedString & aText,
7fd59977 63 const gp_Pnt & aPosition,
64 const gp_Pnt & anEndOfArrow,
65 const gp_Pnt & aCenter,
66 const Standard_Boolean IsMaxRadius,
67 const DsgPrs_ArrowSide ArrowPrs)
68{
7fd59977 69 Handle(Prs3d_LengthAspect) LA = aDrawer->LengthAspect();
70 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
71
b8ddfc2f 72 const Standard_Real dist = aCenter.Distance( aPosition );
73 const Standard_Boolean inside = ( dist <= theval );
74 gp_Pnt EndPoint(inside? anEndOfArrow : aPosition);
75
76 Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(2);
77 aPrims->AddVertex(aCenter);
78 aPrims->AddVertex(EndPoint);
79 Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims);
80
81 // value
82 TCollection_ExtendedString Text(IsMaxRadius? "a = " : "b = ");
83 Text += aText;
7fd59977 84 Prs3d_Text::Draw(aPresentation, LA->TextAspect(), Text, aPosition );
85
b8ddfc2f 86 // arrows
7fd59977 87 gp_Dir arrdir( gp_Vec( aCenter, anEndOfArrow));
88 if (!inside) arrdir.Reverse();
89
b8ddfc2f 90 DsgPrs::ComputeSymbol(aPresentation, LA, anEndOfArrow, anEndOfArrow, arrdir, arrdir, ArrowPrs );
7fd59977 91}
92
93//=======================================================================
94//function : Add
95//purpose :
96//=======================================================================
97
98void DsgPrs_EllipseRadiusPresentation::Add (const Handle(Prs3d_Presentation)& aPresentation,
99 const Handle(Prs3d_Drawer)& aDrawer,
100 const Standard_Real theval,
101 const TCollection_ExtendedString & aText,
102 const gp_Elips & anEllipse,
103 const gp_Pnt & aPosition,
104 const gp_Pnt & anEndOfArrow,
105 const gp_Pnt & aCenter,
106 const Standard_Real uFirst,
107 const Standard_Boolean IsInDomain,
108 const Standard_Boolean IsMaxRadius,
109 const DsgPrs_ArrowSide ArrowPrs)
110{
7fd59977 111 Handle(Prs3d_LengthAspect) LA = aDrawer->LengthAspect();
112 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
b8ddfc2f 113
7fd59977 114 if(!IsInDomain)
b8ddfc2f 115 {
116 const Standard_Real uLast = ElCLib::Parameter ( anEllipse, anEndOfArrow );
117 const Standard_Real Alpha = DsgPrs::DistanceFromApex(anEllipse, anEndOfArrow, uFirst);//length of ellipse arc
118 gp_Vec Vapex(aCenter, ElCLib::Value( uLast, anEllipse )) ;
119 gp_Vec Vpnt(aCenter, ElCLib::Value( uFirst, anEllipse )) ;
120 gp_Dir dir(Vpnt ^ Vapex);
121 Standard_Real parFirst = anEllipse.Position().Direction().IsOpposite( dir, Precision::Angular())? uLast : uFirst;
122 const Standard_Integer NodeNumber = Max (4 , Standard_Integer (50. * Alpha / M_PI));
123 const Standard_Real delta = Alpha / ( NodeNumber - 1 );
124
125 Handle(Graphic3d_ArrayOfPolylines) aPrims = new Graphic3d_ArrayOfPolylines(NodeNumber);
126 for (Standard_Integer i = 0 ; i < NodeNumber; i++, parFirst += delta)
127 aPrims->AddVertex(ElCLib::Value( parFirst, anEllipse ));
128 Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims);
129 }
7fd59977 130 DsgPrs_EllipseRadiusPresentation::Add(aPresentation, aDrawer, theval, aText,
b8ddfc2f 131 aPosition, anEndOfArrow, aCenter, IsMaxRadius, ArrowPrs);
7fd59977 132}
133
134
7fd59977 135//=======================================================================
136//function : Add
137//purpose : // for offset curve
138//=======================================================================
139
140void DsgPrs_EllipseRadiusPresentation::Add (const Handle(Prs3d_Presentation)& aPresentation,
141 const Handle(Prs3d_Drawer)& aDrawer,
142 const Standard_Real theval,
143 const TCollection_ExtendedString & aText,
144 const Handle(Geom_OffsetCurve) & aCurve,
145 const gp_Pnt & aPosition,
146 const gp_Pnt & anEndOfArrow,
147 const gp_Pnt & aCenter,
148 const Standard_Real uFirst,
149 const Standard_Boolean IsInDomain,
150 const Standard_Boolean IsMaxRadius,
151 const DsgPrs_ArrowSide ArrowPrs)
152{
7fd59977 153 Handle(Prs3d_LengthAspect) LA = aDrawer->LengthAspect();
154 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
b8ddfc2f 155
7fd59977 156 if(!IsInDomain)
b8ddfc2f 157 {
158 if(!aCurve->IsCN(1)) return ;
159 gp_Elips aBEllipse = Handle(Geom_Ellipse)::DownCast(aCurve->BasisCurve ())->Elips();
160 const Standard_Real Offset = aCurve->Offset();
161 aBEllipse.SetMajorRadius(aBEllipse.MajorRadius() + Offset);
162 aBEllipse.SetMinorRadius(aBEllipse.MinorRadius() + Offset);
163 const Standard_Real uLast = ElCLib::Parameter ( aBEllipse, anEndOfArrow );
164 const Standard_Real Alpha = DsgPrs::DistanceFromApex(aBEllipse, anEndOfArrow, uFirst);//length of ellipse arc
165 gp_Pnt p1;
166 aCurve->D0(uFirst, p1);
167 gp_Vec Vapex(aCenter, anEndOfArrow) ;
168 gp_Vec Vpnt (aCenter, p1) ;
169 gp_Dir dir(Vpnt ^ Vapex);
170 Standard_Real parFirst = aCurve->Direction().IsOpposite( dir, Precision::Angular())? uLast : uFirst;
171 const Standard_Integer NodeNumber = Max (4 , Standard_Integer (50. * Alpha / M_PI));
172 const Standard_Real delta = Alpha / ( NodeNumber - 1 );
173
174 Handle(Graphic3d_ArrayOfPolylines) aPrims = new Graphic3d_ArrayOfPolylines(NodeNumber);
175 for (Standard_Integer i = 0 ; i < NodeNumber; i++, parFirst += delta)
7fd59977 176 {
b8ddfc2f 177 aCurve->D0( parFirst, p1 );
178 aPrims->AddVertex(p1);
7fd59977 179 }
b8ddfc2f 180 Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims);
181 }
7fd59977 182 DsgPrs_EllipseRadiusPresentation::Add(aPresentation, aDrawer, theval, aText,
b8ddfc2f 183 aPosition, anEndOfArrow, aCenter, IsMaxRadius, ArrowPrs);
7fd59977 184}