Commit | Line | Data |
---|---|---|
b311480e | 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 | |
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 | // modified 12-january-98 |
22 | // Sergey ZARITCHNY | |
7fd59977 | 23 | // szy |
24 | #include <DsgPrs_DiameterPresentation.ixx> | |
25 | ||
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> | |
32 | ||
33 | #include <Graphic3d_Group.hxx> | |
b8ddfc2f | 34 | #include <Graphic3d_ArrayOfSegments.hxx> |
7fd59977 | 35 | |
36 | #include <gp_Dir.hxx> | |
37 | #include <gp_Pnt.hxx> | |
38 | #include <gp_Vec.hxx> | |
39 | ||
40 | #include <ElCLib.hxx> | |
41 | ||
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> | |
49 | #include <DsgPrs.hxx> | |
50 | ||
51 | //========================================================================== | |
52 | // function : DsgPrs_DiameterPresentation::Add | |
81bba717 | 53 | // purpose : it is possible to choose the symbol of extremities of the face (arrow, point ...) |
7fd59977 | 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 ) | |
62 | { | |
7fd59977 | 63 | Handle(Prs3d_LengthAspect) LA = aDrawer->LengthAspect(); |
64 | Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect()); | |
65 | ||
66 | Standard_Real parat = ElCLib::Parameter(aCircle, AttachmentPoint); | |
67 | gp_Pnt ptoncirc = ElCLib::Value (parat, aCircle); | |
68 | ||
81bba717 | 69 | // sideline |
7fd59977 | 70 | gp_Pnt center = aCircle.Location(); |
71 | gp_Vec vecrap (ptoncirc,center); | |
72 | ||
73 | Standard_Real dist = center.Distance(AttachmentPoint); | |
74 | Standard_Real aRadius = aCircle.Radius(); | |
b8ddfc2f | 75 | Standard_Boolean inside = (dist < aRadius); |
7fd59977 | 76 | |
77 | gp_Pnt pt1 = AttachmentPoint; | |
b8ddfc2f | 78 | if (inside) { |
7fd59977 | 79 | pt1 = ptoncirc; |
80 | dist = aRadius; | |
7fd59977 | 81 | } |
82 | vecrap.Normalize(); | |
83 | vecrap *= (dist+aRadius); | |
b8ddfc2f | 84 | gp_Pnt OppositePoint = pt1.Translated(vecrap); |
7fd59977 | 85 | |
b8ddfc2f | 86 | Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(2); |
87 | aPrims->AddVertex(pt1); | |
88 | aPrims->AddVertex(OppositePoint); | |
89 | Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims); | |
7fd59977 | 90 | |
91 | // value | |
92 | TCollection_ExtendedString Text = aText; | |
93 | if(IsDiamSymbol) | |
94 | Text = TCollection_ExtendedString("\330 ") + aText; // VRO (2007-05-17) inserted a blank. | |
95 | Prs3d_Text::Draw(aPresentation, LA->TextAspect(), Text, AttachmentPoint); | |
96 | ||
97 | // arrows | |
7fd59977 | 98 | gp_Dir arrdir (vecrap); |
99 | if (inside) arrdir.Reverse(); | |
100 | ||
7fd59977 | 101 | gp_Vec vecrap2 = vecrap; |
102 | gp_Pnt ptoncirc2 = ptoncirc; | |
103 | gp_Dir arrdir2 = arrdir; | |
104 | vecrap2.Normalize(); | |
105 | vecrap2 *= (aCircle.Radius() * 2.); | |
106 | ptoncirc2.Translate (vecrap2); | |
107 | arrdir2.Reverse(); | |
108 | ||
109 | DsgPrs::ComputeSymbol(aPresentation,LA,ptoncirc,ptoncirc2,arrdir,arrdir2,ArrowPrs); | |
110 | } | |
111 | ||
112 | ||
113 | static Standard_Boolean DsgPrs_InDomain(const Standard_Real fpar, | |
114 | const Standard_Real lpar, | |
115 | const Standard_Real para) | |
116 | { | |
117 | if (fpar >= 0.) { | |
118 | if(lpar > fpar) | |
119 | return ((para >= fpar) && (para <= lpar)); | |
120 | else { // fpar > lpar | |
b8ddfc2f | 121 | Standard_Real delta = 2.*M_PI-fpar; |
7fd59977 | 122 | Standard_Real lp, par, fp; |
123 | lp = lpar + delta; | |
124 | par = para + delta; | |
c6541a0c D |
125 | while(lp > 2*M_PI) lp-=2*M_PI; |
126 | while(par > 2*M_PI) par-=2*M_PI; | |
7fd59977 | 127 | fp = 0.; |
128 | return ((par >= fp) && (par <= lp)); | |
129 | } | |
7fd59977 | 130 | } |
c6541a0c | 131 | if (para >= (fpar+2*M_PI)) return Standard_True; |
7fd59977 | 132 | if (para <= lpar) return Standard_True; |
133 | return Standard_False; | |
134 | } | |
135 | ||
136 | ||
137 | //======================================================================= | |
138 | //function : DsgPrs_DiameterPresentation::Add | |
139 | //purpose : SZY 12-february-98 | |
140 | //======================================================================= | |
141 | ||
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 ) | |
151 | { | |
152 | Standard_Real fpara = uFirst; | |
153 | Standard_Real lpara = uLast; | |
b8ddfc2f | 154 | while (lpara > 2.*M_PI) { |
155 | fpara -= 2.*M_PI; | |
156 | lpara -= 2.*M_PI; | |
7fd59977 | 157 | } |
158 | ||
159 | Handle(Prs3d_LengthAspect) LA = aDrawer->LengthAspect(); | |
7fd59977 | 160 | Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect()); |
b8ddfc2f | 161 | Standard_Real parEndOfArrow = ElCLib::Parameter(aCircle,AttachmentPoint); |
7fd59977 | 162 | gp_Pnt EndOfArrow; |
81bba717 | 163 | gp_Pnt DrawPosition = AttachmentPoint;// point of attachment |
7fd59977 | 164 | Standard_Boolean otherside = Standard_False; |
165 | ||
166 | gp_Pnt Center = aCircle.Location(); | |
167 | gp_Pnt FirstPoint = ElCLib::Value(uFirst, aCircle); | |
168 | gp_Pnt SecondPoint = ElCLib::Value(uLast, aCircle); | |
169 | ||
170 | if ( !DsgPrs_InDomain(fpara,lpara,parEndOfArrow)) { | |
c6541a0c D |
171 | Standard_Real otherpar = parEndOfArrow + M_PI;// not in domain |
172 | if (otherpar > 2*M_PI) otherpar -= 2*M_PI; | |
7fd59977 | 173 | if (DsgPrs_InDomain(fpara,lpara,otherpar)) { |
174 | parEndOfArrow = otherpar; // parameter on circle | |
175 | EndOfArrow = ElCLib::Value(parEndOfArrow, aCircle); | |
176 | otherside = Standard_True; | |
177 | } | |
178 | else { | |
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)) | |
b8ddfc2f | 184 | { |
185 | EndOfArrow = FirstPoint; //*** | |
186 | DrawPosition = ElCLib::Value(ElCLib::Parameter( L1, AttachmentPoint ), L1); | |
187 | } | |
7fd59977 | 188 | else |
b8ddfc2f | 189 | { |
190 | EndOfArrow = SecondPoint; //*** | |
191 | DrawPosition = ElCLib::Value(ElCLib::Parameter( L2, AttachmentPoint ), L2); | |
192 | } | |
7fd59977 | 193 | } |
7fd59977 | 194 | } |
195 | else { | |
196 | EndOfArrow = ElCLib::Value(parEndOfArrow, aCircle); | |
197 | DrawPosition = AttachmentPoint; | |
198 | } | |
7fd59977 | 199 | |
b8ddfc2f | 200 | Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(2); |
201 | aPrims->AddVertex(DrawPosition); | |
202 | aPrims->AddVertex(EndOfArrow); | |
203 | Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims); | |
7fd59977 | 204 | |
205 | // text | |
206 | TCollection_ExtendedString Text = aText; | |
207 | if(IsDiamSymbol) | |
208 | Text = TCollection_ExtendedString("\330 ") + Text;// => \330 | \370? | |
209 | Prs3d_Text::Draw(aPresentation,LA->TextAspect(),Text,DrawPosition); | |
210 | ||
b8ddfc2f | 211 | // Add presentation of arrow |
7fd59977 | 212 | gp_Dir DirOfArrow(gp_Vec(DrawPosition, EndOfArrow).XYZ()); |
b8ddfc2f | 213 | DsgPrs::ComputeSymbol(aPresentation, LA, EndOfArrow, EndOfArrow, DirOfArrow, DirOfArrow, ArrowPrs); |
7fd59977 | 214 | } |