1 // Created on: 1996-08-21
2 // Created by: Jacques MINOT
3 // Copyright (c) 1996-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 12-january-98
24 #include <DsgPrs_DiameterPresentation.ixx>
26 #include <Prs3d_LineAspect.hxx>
27 #include <Prs3d_TextAspect.hxx>
28 #include <Prs3d_LengthAspect.hxx>
29 #include <Prs3d_Arrow.hxx>
30 #include <Prs3d_Text.hxx>
31 #include <Prs3d_ArrowAspect.hxx>
33 #include <Graphic3d_Group.hxx>
34 #include <Graphic3d_ArrayOfSegments.hxx>
42 #include <Graphic3d_Vertex.hxx>
43 #include <Graphic3d_AspectMarker3d.hxx>
44 #include <Graphic3d_AspectLine3d.hxx>
45 #include <Aspect_TypeOfLine.hxx>
46 #include <Aspect_TypeOfMarker.hxx>
47 #include <Aspect_AspectMarker.hxx>
48 #include <Quantity_Color.hxx>
51 //==========================================================================
52 // function : DsgPrs_DiameterPresentation::Add
53 // purpose : it is possible to choose the symbol of extremities of the face (arrow, point ...)
54 //==========================================================================
55 void DsgPrs_DiameterPresentation::Add (const Handle(Prs3d_Presentation)& aPresentation,
56 const Handle(Prs3d_Drawer)& aDrawer,
57 const TCollection_ExtendedString& aText,
58 const gp_Pnt& AttachmentPoint,
59 const gp_Circ& aCircle,
60 const DsgPrs_ArrowSide ArrowPrs,
61 const Standard_Boolean IsDiamSymbol )
63 Handle(Prs3d_LengthAspect) LA = aDrawer->LengthAspect();
64 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
66 Standard_Real parat = ElCLib::Parameter(aCircle, AttachmentPoint);
67 gp_Pnt ptoncirc = ElCLib::Value (parat, aCircle);
70 gp_Pnt center = aCircle.Location();
71 gp_Vec vecrap (ptoncirc,center);
73 Standard_Real dist = center.Distance(AttachmentPoint);
74 Standard_Real aRadius = aCircle.Radius();
75 Standard_Boolean inside = (dist < aRadius);
77 gp_Pnt pt1 = AttachmentPoint;
83 vecrap *= (dist+aRadius);
84 gp_Pnt OppositePoint = pt1.Translated(vecrap);
86 Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(2);
87 aPrims->AddVertex(pt1);
88 aPrims->AddVertex(OppositePoint);
89 Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims);
92 TCollection_ExtendedString Text = aText;
94 Text = TCollection_ExtendedString("\330 ") + aText; // VRO (2007-05-17) inserted a blank.
95 Prs3d_Text::Draw(aPresentation, LA->TextAspect(), Text, AttachmentPoint);
98 gp_Dir arrdir (vecrap);
99 if (inside) arrdir.Reverse();
101 gp_Vec vecrap2 = vecrap;
102 gp_Pnt ptoncirc2 = ptoncirc;
103 gp_Dir arrdir2 = arrdir;
105 vecrap2 *= (aCircle.Radius() * 2.);
106 ptoncirc2.Translate (vecrap2);
109 DsgPrs::ComputeSymbol(aPresentation,LA,ptoncirc,ptoncirc2,arrdir,arrdir2,ArrowPrs);
113 static Standard_Boolean DsgPrs_InDomain(const Standard_Real fpar,
114 const Standard_Real lpar,
115 const Standard_Real para)
119 return ((para >= fpar) && (para <= lpar));
120 else { // fpar > lpar
121 Standard_Real delta = 2.*M_PI-fpar;
122 Standard_Real lp, par, fp;
125 while(lp > 2*M_PI) lp-=2*M_PI;
126 while(par > 2*M_PI) par-=2*M_PI;
128 return ((par >= fp) && (par <= lp));
131 if (para >= (fpar+2*M_PI)) return Standard_True;
132 if (para <= lpar) return Standard_True;
133 return Standard_False;
137 //=======================================================================
138 //function : DsgPrs_DiameterPresentation::Add
139 //purpose : SZY 12-february-98
140 //=======================================================================
142 void DsgPrs_DiameterPresentation::Add (const Handle(Prs3d_Presentation)& aPresentation,
143 const Handle(Prs3d_Drawer)& aDrawer,
144 const TCollection_ExtendedString& aText,
145 const gp_Pnt& AttachmentPoint,
146 const gp_Circ& aCircle,
147 const Standard_Real uFirst,
148 const Standard_Real uLast,
149 const DsgPrs_ArrowSide ArrowPrs,//ArrowSide
150 const Standard_Boolean IsDiamSymbol )
152 Standard_Real fpara = uFirst;
153 Standard_Real lpara = uLast;
154 while (lpara > 2.*M_PI) {
159 Handle(Prs3d_LengthAspect) LA = aDrawer->LengthAspect();
160 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
161 Standard_Real parEndOfArrow = ElCLib::Parameter(aCircle,AttachmentPoint);
163 gp_Pnt DrawPosition = AttachmentPoint;// point of attachment
164 Standard_Boolean otherside = Standard_False;
166 gp_Pnt Center = aCircle.Location();
167 gp_Pnt FirstPoint = ElCLib::Value(uFirst, aCircle);
168 gp_Pnt SecondPoint = ElCLib::Value(uLast, aCircle);
170 if ( !DsgPrs_InDomain(fpara,lpara,parEndOfArrow)) {
171 Standard_Real otherpar = parEndOfArrow + M_PI;// not in domain
172 if (otherpar > 2*M_PI) otherpar -= 2*M_PI;
173 if (DsgPrs_InDomain(fpara,lpara,otherpar)) {
174 parEndOfArrow = otherpar; // parameter on circle
175 EndOfArrow = ElCLib::Value(parEndOfArrow, aCircle);
176 otherside = Standard_True;
179 gp_Dir dir1(gp_Vec(Center, FirstPoint));
180 gp_Dir dir2(gp_Vec(Center, SecondPoint));
181 gp_Lin L1( Center, dir1 );
182 gp_Lin L2( Center, dir2 );
183 if(L1.Distance(AttachmentPoint) < L2.Distance(AttachmentPoint))
185 EndOfArrow = FirstPoint; //***
186 DrawPosition = ElCLib::Value(ElCLib::Parameter( L1, AttachmentPoint ), L1);
190 EndOfArrow = SecondPoint; //***
191 DrawPosition = ElCLib::Value(ElCLib::Parameter( L2, AttachmentPoint ), L2);
196 EndOfArrow = ElCLib::Value(parEndOfArrow, aCircle);
197 DrawPosition = AttachmentPoint;
200 Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(2);
201 aPrims->AddVertex(DrawPosition);
202 aPrims->AddVertex(EndOfArrow);
203 Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims);
206 TCollection_ExtendedString Text = aText;
208 Text = TCollection_ExtendedString("\330 ") + Text;// => \330 | \370?
209 Prs3d_Text::Draw(aPresentation,LA->TextAspect(),Text,DrawPosition);
211 // Add presentation of arrow
212 gp_Dir DirOfArrow(gp_Vec(DrawPosition, EndOfArrow).XYZ());
213 DsgPrs::ComputeSymbol(aPresentation, LA, EndOfArrow, EndOfArrow, DirOfArrow, DirOfArrow, ArrowPrs);