Integration of OCCT 6.5.0 from SVN
[occt.git] / src / DsgPrs / DsgPrs_RadiusPresentation.cxx
1 // File:        DsgPrs_RadiusPresentation.cxx
2 // Created:     Wed Mar  1 15:50:43 1995
3 // Author:      Arnaud BOUZY
4 //              <adn>
5 //modified      20-feb-98 by <SZY>
6 //              Sergei Zaritchny
7
8 #include <DsgPrs_RadiusPresentation.ixx>
9 #include <gp_Lin.hxx>
10 #include <gp_Dir.hxx>
11 #include <gp_Circ.hxx>
12 #include <ElCLib.hxx>
13 #include <Graphic3d_Group.hxx>
14 #include <Graphic3d_Array1OfVertex.hxx>
15 #include <Prs3d_Arrow.hxx>
16 #include <Prs3d_ArrowAspect.hxx>
17 #include <Prs3d_LineAspect.hxx>
18 #include <Prs3d_LengthAspect.hxx>
19 #include <Prs3d_Text.hxx>
20
21 #include <Graphic3d_Vertex.hxx>
22 #include <Graphic3d_AspectMarker3d.hxx>
23 #include <Graphic3d_AspectLine3d.hxx>
24 #include <Aspect_TypeOfLine.hxx>
25 #include <Aspect_TypeOfMarker.hxx>
26 #include <Aspect_AspectMarker.hxx>
27 #include <Quantity_Color.hxx>
28 #include <DsgPrs.hxx>
29 #include <Precision.hxx>
30 #include <gce_MakeLin.hxx>
31 #include <gce_MakeDir.hxx>
32
33
34 static Standard_Boolean DsgPrs_InDomain(const Standard_Real fpar,
35                                         const Standard_Real lpar,
36                                         const Standard_Real para) 
37 {
38   if (fpar >= 0.) {
39     return ((para >= fpar) && (para <= lpar));
40   }
41   if (para >= (fpar+2*PI)) return Standard_True;
42   if (para <= lpar) return Standard_True;
43   return Standard_False;
44 }
45
46 //=======================================================================
47 //function : Add
48 //purpose  : 
49 //=======================================================================
50
51 void DsgPrs_RadiusPresentation::Add (const Handle(Prs3d_Presentation)& aPresentation,
52                                      const Handle(Prs3d_Drawer)& aDrawer,
53                                      const TCollection_ExtendedString& aText,
54                                      const gp_Pnt& AttachmentPoint,
55                                      const gp_Circ& aCircle,
56                                      const Standard_Real firstparam,
57                                      const Standard_Real lastparam,
58                                      const Standard_Boolean drawFromCenter,
59                                      const Standard_Boolean reverseArrow) 
60 {
61   Standard_Real fpara = firstparam;
62   Standard_Real lpara = lastparam;
63   while (lpara > 2*PI) {
64     fpara -= 2*PI;
65     lpara -= 2*PI;
66   }
67   Handle(Prs3d_LengthAspect) LA = aDrawer->LengthAspect();
68   Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
69   Standard_Real parat = ElCLib::Parameter(aCircle,AttachmentPoint);
70   gp_Pnt attpoint = AttachmentPoint;
71   Standard_Boolean otherside = Standard_False;
72   if ( !DsgPrs_InDomain(fpara,lpara,parat)) {
73     Standard_Real otherpar = parat + PI;
74     if (otherpar > 2*PI) otherpar -= 2*PI;
75     if (DsgPrs_InDomain(fpara,lpara,otherpar)) {
76       parat = otherpar;
77       otherside = Standard_True;
78     }
79     else {
80       Standard_Real ecartpar = Min(Abs(fpara-parat),
81                                    Abs(lpara-parat));
82       Standard_Real ecartoth = Min(Abs(fpara-otherpar),
83                                    Abs(lpara-otherpar));
84       if (ecartpar <= ecartoth) {
85         if (parat < fpara) {
86           parat = fpara;
87         }
88         else {
89           parat = lpara;
90         }
91       }
92       else {
93         otherside = Standard_True;
94         if (otherpar < fpara) {
95           parat = fpara;
96         }
97         else {
98           parat = lpara;
99         }
100       }
101       gp_Pnt ptdir = ElCLib::Value(parat,aCircle);
102       gp_Lin lsup(aCircle.Location(),
103                   gp_Dir(ptdir.XYZ()-aCircle.Location().XYZ()));
104       Standard_Real parpos = ElCLib::Parameter(lsup,AttachmentPoint);
105       attpoint = ElCLib::Value(parpos,lsup);
106     }
107   }
108   gp_Pnt ptoncirc = ElCLib::Value(parat,aCircle);
109   gp_Lin L (aCircle.Location(),gp_Dir(attpoint.XYZ()-aCircle.Location().XYZ()));
110   gp_Pnt firstpoint = attpoint;
111   gp_Pnt drawtopoint = ptoncirc;
112   if (drawFromCenter && !otherside) {
113     Standard_Real uatt = ElCLib::Parameter(L,attpoint);
114     Standard_Real uptc = ElCLib::Parameter(L,ptoncirc);
115     if (Abs(uatt) > Abs(uptc)) {
116       drawtopoint = aCircle.Location();
117     }
118     else {
119       firstpoint = aCircle.Location();
120     }
121   }
122
123   Graphic3d_Array1OfVertex V(1,2);
124
125   Quantity_Length X,Y,Z;
126
127   firstpoint.Coord(X,Y,Z);
128   V(1).SetCoord(X,Y,Z);
129
130   drawtopoint.Coord(X,Y,Z);
131   V(2).SetCoord(X,Y,Z);
132
133   Prs3d_Root::CurrentGroup(aPresentation)->Polyline(V);
134
135   gp_Dir arrdir = L.Direction();
136   if (reverseArrow) {
137     arrdir.Reverse();
138   }
139   // fleche
140   Prs3d_Arrow::Draw(aPresentation,ptoncirc,arrdir,
141                     LA->Arrow1Aspect()->Angle(),
142                     LA->Arrow1Aspect()->Length());
143
144   // texte
145   Prs3d_Text::Draw(aPresentation,LA->TextAspect(),aText,attpoint);
146   
147 }
148
149 //=======================================================================
150 //function : DsgPrs_RadiusPresentation::Add
151 //purpose  : SZY 20-february-98 
152 //         : adds radius representation according drawFromCenter value
153 //=======================================================================
154
155 void DsgPrs_RadiusPresentation::Add( const Handle(Prs3d_Presentation)& aPresentation,
156                                      const Handle(Prs3d_Drawer)& aDrawer,
157                                      const TCollection_ExtendedString& aText,
158                                      const gp_Pnt& AttachmentPoint,
159                                      const gp_Pnt& Center,
160                                      const gp_Pnt& EndOfArrow,
161                                      const DsgPrs_ArrowSide ArrowPrs,
162                                      const Standard_Boolean drawFromCenter,
163                                      const Standard_Boolean reverseArrow)
164 {
165   Handle( Prs3d_LengthAspect ) LA = aDrawer->LengthAspect();
166   Prs3d_Root::CurrentGroup( aPresentation )->SetPrimitivesAspect( LA->LineAspect()->Aspect() );
167
168   Graphic3d_Array1OfVertex VertexArray( 1, 2 );
169   gp_Pnt  LineOrigin, LineEnd;
170   Quantity_Length X,Y,Z;
171
172   DsgPrs::ComputeRadiusLine( Center, EndOfArrow, AttachmentPoint, drawFromCenter,
173                             LineOrigin, LineEnd);
174 //
175   LineOrigin.Coord( X, Y, Z );
176   VertexArray(1).SetCoord( X, Y, Z );
177
178   LineEnd.Coord( X, Y, Z );
179   VertexArray(2).SetCoord( X, Y, Z );
180
181   Prs3d_Root::CurrentGroup( aPresentation )->Polyline( VertexArray );
182   // text
183   Prs3d_Text::Draw( aPresentation, LA->TextAspect(), aText, AttachmentPoint );
184
185   gp_Dir ArrowDir = gce_MakeDir( LineOrigin , LineEnd );
186   if (reverseArrow)
187     ArrowDir.Reverse();
188   DsgPrs::ComputeSymbol( aPresentation, LA, Center, EndOfArrow, ArrowDir.Reversed(), ArrowDir,
189                         ArrowPrs, drawFromCenter );
190 }
191