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_Array1OfVertex.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));
57 if (para >= (fpar+2*M_PI)) return Standard_True;
58 if (para <= lpar) return Standard_True;
59 return Standard_False;
62 //=======================================================================
65 //=======================================================================
67 void DsgPrs_RadiusPresentation::Add (const Handle(Prs3d_Presentation)& aPresentation,
68 const Handle(Prs3d_Drawer)& aDrawer,
69 const TCollection_ExtendedString& aText,
70 const gp_Pnt& AttachmentPoint,
71 const gp_Circ& aCircle,
72 const Standard_Real firstparam,
73 const Standard_Real lastparam,
74 const Standard_Boolean drawFromCenter,
75 const Standard_Boolean reverseArrow)
77 Standard_Real fpara = firstparam;
78 Standard_Real lpara = lastparam;
79 while (lpara > 2*M_PI) {
83 Handle(Prs3d_LengthAspect) LA = aDrawer->LengthAspect();
84 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 Standard_Real ecartpar = Min(Abs(fpara-parat),
98 Standard_Real ecartoth = Min(Abs(fpara-otherpar),
100 if (ecartpar <= ecartoth) {
109 otherside = Standard_True;
110 if (otherpar < fpara) {
117 gp_Pnt ptdir = ElCLib::Value(parat,aCircle);
118 gp_Lin lsup(aCircle.Location(),
119 gp_Dir(ptdir.XYZ()-aCircle.Location().XYZ()));
120 Standard_Real parpos = ElCLib::Parameter(lsup,AttachmentPoint);
121 attpoint = ElCLib::Value(parpos,lsup);
124 gp_Pnt ptoncirc = ElCLib::Value(parat,aCircle);
125 gp_Lin L (aCircle.Location(),gp_Dir(attpoint.XYZ()-aCircle.Location().XYZ()));
126 gp_Pnt firstpoint = attpoint;
127 gp_Pnt drawtopoint = ptoncirc;
128 if (drawFromCenter && !otherside) {
129 Standard_Real uatt = ElCLib::Parameter(L,attpoint);
130 Standard_Real uptc = ElCLib::Parameter(L,ptoncirc);
131 if (Abs(uatt) > Abs(uptc)) {
132 drawtopoint = aCircle.Location();
135 firstpoint = aCircle.Location();
139 Graphic3d_Array1OfVertex V(1,2);
141 Quantity_Length X,Y,Z;
143 firstpoint.Coord(X,Y,Z);
144 V(1).SetCoord(X,Y,Z);
146 drawtopoint.Coord(X,Y,Z);
147 V(2).SetCoord(X,Y,Z);
149 Prs3d_Root::CurrentGroup(aPresentation)->Polyline(V);
151 gp_Dir arrdir = L.Direction();
156 Prs3d_Arrow::Draw(aPresentation,ptoncirc,arrdir,
157 LA->Arrow1Aspect()->Angle(),
158 LA->Arrow1Aspect()->Length());
161 Prs3d_Text::Draw(aPresentation,LA->TextAspect(),aText,attpoint);
165 //=======================================================================
166 //function : DsgPrs_RadiusPresentation::Add
167 //purpose : SZY 20-february-98
168 // : adds radius representation according drawFromCenter value
169 //=======================================================================
171 void DsgPrs_RadiusPresentation::Add( const Handle(Prs3d_Presentation)& aPresentation,
172 const Handle(Prs3d_Drawer)& aDrawer,
173 const TCollection_ExtendedString& aText,
174 const gp_Pnt& AttachmentPoint,
175 const gp_Pnt& Center,
176 const gp_Pnt& EndOfArrow,
177 const DsgPrs_ArrowSide ArrowPrs,
178 const Standard_Boolean drawFromCenter,
179 const Standard_Boolean reverseArrow)
181 Handle( Prs3d_LengthAspect ) LA = aDrawer->LengthAspect();
182 Prs3d_Root::CurrentGroup( aPresentation )->SetPrimitivesAspect( LA->LineAspect()->Aspect() );
184 Graphic3d_Array1OfVertex VertexArray( 1, 2 );
185 gp_Pnt LineOrigin, LineEnd;
186 Quantity_Length X,Y,Z;
188 DsgPrs::ComputeRadiusLine( Center, EndOfArrow, AttachmentPoint, drawFromCenter,
189 LineOrigin, LineEnd);
191 LineOrigin.Coord( X, Y, Z );
192 VertexArray(1).SetCoord( X, Y, Z );
194 LineEnd.Coord( X, Y, Z );
195 VertexArray(2).SetCoord( X, Y, Z );
197 Prs3d_Root::CurrentGroup( aPresentation )->Polyline( VertexArray );
199 Prs3d_Text::Draw( aPresentation, LA->TextAspect(), aText, AttachmentPoint );
201 gp_Dir ArrowDir = gce_MakeDir( LineOrigin , LineEnd );
204 DsgPrs::ComputeSymbol( aPresentation, LA, Center, EndOfArrow, ArrowDir.Reversed(), ArrowDir,
205 ArrowPrs, drawFromCenter );