1 // Created on: 1995-03-01
2 // Created by: Arnaud BOUZY
3 // Copyright (c) 1995-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.
21 //modified 20-feb-98 by <SZY>
24 #include <DsgPrs_RadiusPresentation.ixx>
27 #include <gp_Circ.hxx>
29 #include <Graphic3d_Group.hxx>
30 #include <Graphic3d_ArrayOfSegments.hxx>
31 #include <Prs3d_Arrow.hxx>
32 #include <Prs3d_ArrowAspect.hxx>
33 #include <Prs3d_LineAspect.hxx>
34 #include <Prs3d_LengthAspect.hxx>
35 #include <Prs3d_Text.hxx>
37 #include <Graphic3d_Vertex.hxx>
38 #include <Graphic3d_AspectMarker3d.hxx>
39 #include <Graphic3d_AspectLine3d.hxx>
40 #include <Aspect_TypeOfLine.hxx>
41 #include <Aspect_TypeOfMarker.hxx>
42 #include <Aspect_AspectMarker.hxx>
43 #include <Quantity_Color.hxx>
45 #include <Precision.hxx>
46 #include <gce_MakeLin.hxx>
47 #include <gce_MakeDir.hxx>
50 static Standard_Boolean DsgPrs_InDomain(const Standard_Real fpar,
51 const Standard_Real lpar,
52 const Standard_Real para)
55 return ((para >= fpar) && (para <= lpar));
56 if (para >= (fpar+2.*M_PI)) return Standard_True;
57 if (para <= lpar) return Standard_True;
58 return Standard_False;
61 //=======================================================================
64 //=======================================================================
66 void DsgPrs_RadiusPresentation::Add (const Handle(Prs3d_Presentation)& aPresentation,
67 const Handle(Prs3d_Drawer)& aDrawer,
68 const TCollection_ExtendedString& aText,
69 const gp_Pnt& AttachmentPoint,
70 const gp_Circ& aCircle,
71 const Standard_Real firstparam,
72 const Standard_Real lastparam,
73 const Standard_Boolean drawFromCenter,
74 const Standard_Boolean reverseArrow)
76 Standard_Real fpara = firstparam;
77 Standard_Real lpara = lastparam;
78 while (lpara > 2.*M_PI) {
82 Handle(Prs3d_LengthAspect) LA = aDrawer->LengthAspect();
83 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
85 Standard_Real parat = ElCLib::Parameter(aCircle,AttachmentPoint);
86 gp_Pnt attpoint = AttachmentPoint;
87 Standard_Boolean otherside = Standard_False;
88 if ( !DsgPrs_InDomain(fpara,lpara,parat)) {
89 Standard_Real otherpar = parat + M_PI;
90 if (otherpar > 2.*M_PI) otherpar -= 2.*M_PI;
91 if (DsgPrs_InDomain(fpara,lpara,otherpar)) {
93 otherside = Standard_True;
96 const Standard_Real ecartpar = Min(Abs(fpara-parat),Abs(lpara-parat));
97 const Standard_Real ecartoth = Min(Abs(fpara-otherpar),Abs(lpara-otherpar));
98 if (ecartpar <= ecartoth) {
99 parat = (parat < fpara)? fpara : lpara;
102 otherside = Standard_True;
103 parat = (otherpar < fpara)? fpara : lpara;
105 gp_Pnt ptdir = ElCLib::Value(parat,aCircle);
106 gp_Lin lsup(aCircle.Location(),gp_Dir(ptdir.XYZ()-aCircle.Location().XYZ()));
107 const Standard_Real parpos = ElCLib::Parameter(lsup,AttachmentPoint);
108 attpoint = ElCLib::Value(parpos,lsup);
111 gp_Pnt ptoncirc = ElCLib::Value(parat,aCircle);
112 gp_Lin L (aCircle.Location(),gp_Dir(attpoint.XYZ()-aCircle.Location().XYZ()));
113 gp_Pnt firstpoint = attpoint;
114 gp_Pnt drawtopoint = ptoncirc;
115 if (drawFromCenter && !otherside) {
116 const Standard_Real uatt = ElCLib::Parameter(L,attpoint);
117 const Standard_Real uptc = ElCLib::Parameter(L,ptoncirc);
118 if (Abs(uatt) > Abs(uptc))
119 drawtopoint = aCircle.Location();
121 firstpoint = aCircle.Location();
124 Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(2);
125 aPrims->AddVertex(firstpoint);
126 aPrims->AddVertex(drawtopoint);
127 Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims);
129 gp_Dir arrdir = L.Direction();
134 Prs3d_Arrow::Draw(aPresentation,ptoncirc,arrdir,LA->Arrow1Aspect()->Angle(),LA->Arrow1Aspect()->Length());
137 Prs3d_Text::Draw(aPresentation,LA->TextAspect(),aText,attpoint);
140 //=======================================================================
141 //function : DsgPrs_RadiusPresentation::Add
142 //purpose : SZY 20-february-98
143 // : adds radius representation according drawFromCenter value
144 //=======================================================================
146 void DsgPrs_RadiusPresentation::Add( const Handle(Prs3d_Presentation)& aPresentation,
147 const Handle(Prs3d_Drawer)& aDrawer,
148 const TCollection_ExtendedString& aText,
149 const gp_Pnt& AttachmentPoint,
150 const gp_Pnt& Center,
151 const gp_Pnt& EndOfArrow,
152 const DsgPrs_ArrowSide ArrowPrs,
153 const Standard_Boolean drawFromCenter,
154 const Standard_Boolean reverseArrow)
156 Handle( Prs3d_LengthAspect ) LA = aDrawer->LengthAspect();
157 Prs3d_Root::CurrentGroup( aPresentation )->SetPrimitivesAspect( LA->LineAspect()->Aspect() );
159 gp_Pnt LineOrigin, LineEnd;
160 DsgPrs::ComputeRadiusLine(Center, EndOfArrow, AttachmentPoint, drawFromCenter, LineOrigin, LineEnd);
162 Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(2);
163 aPrims->AddVertex(LineOrigin);
164 aPrims->AddVertex(LineEnd);
165 Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims);
168 Prs3d_Text::Draw( aPresentation, LA->TextAspect(), aText, AttachmentPoint );
170 gp_Dir ArrowDir = gce_MakeDir( LineOrigin , LineEnd );
173 DsgPrs::ComputeSymbol( aPresentation, LA, Center, EndOfArrow, ArrowDir.Reversed(), ArrowDir, ArrowPrs, drawFromCenter );