6eccd7c156d8ac06748bc7b621c9316349580145
[occt.git] / src / DsgPrs / DsgPrs_IdenticPresentation.cxx
1 // Created on: 1997-01-03
2 // Created by: Flore Lantheaume
3 // Copyright (c) 1997-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
21
22
23 #include <DsgPrs_IdenticPresentation.ixx>
24
25 #include <Graphic3d_Group.hxx>
26 #include <Graphic3d_Array1OfVertex.hxx>
27 #include <Graphic3d_AspectMarker3d.hxx>
28 #include <Graphic3d_AspectLine3d.hxx>
29
30 #include <Prs3d_LineAspect.hxx>
31 #include <Prs3d_LengthAspect.hxx>
32 #include <Prs3d_Text.hxx>
33
34 #include <TCollection_AsciiString.hxx>
35
36 #include <gp_Vec.hxx>
37 #include <gp_Dir.hxx>
38
39 #include <ElCLib.hxx>
40
41 #include <Precision.hxx>
42 #include <gp_Elips.hxx>
43
44 void DsgPrs_IdenticPresentation::Add( const Handle(Prs3d_Presentation)& aPresentation,
45                                       const Handle(Prs3d_Drawer)& aDrawer,
46                                       const TCollection_ExtendedString& aText,
47                                       const gp_Pnt& aPntAttach,
48                                       const gp_Pnt& aPntOffset)
49 {
50   Handle(Prs3d_LengthAspect) LA = aDrawer->LengthAspect();
51   Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
52
53   Graphic3d_Array1OfVertex V(1,2);
54   V(1).SetCoord(aPntAttach.X(), aPntAttach.Y(), aPntAttach.Z());
55   V(2).SetCoord(aPntOffset.X(), aPntOffset.Y(), aPntOffset.Z());
56
57   // trait de cote 
58   Prs3d_Root::CurrentGroup(aPresentation)->Polyline(V);
59
60   // On ajoute un rond au point d'attache
61   Prs3d_Root::NewGroup(aPresentation);
62   Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
63   Handle(Graphic3d_AspectMarker3d) MarkerAsp = new Graphic3d_AspectMarker3d();
64   MarkerAsp->SetType(Aspect_TOM_BALL);
65   MarkerAsp->SetScale(0.8);
66   Quantity_Color acolor;
67   Aspect_TypeOfLine atype;
68   Standard_Real awidth;
69   LA->LineAspect()->Aspect()->Values(acolor, atype, awidth);
70   MarkerAsp->SetColor(acolor);
71   Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(MarkerAsp);
72   Graphic3d_Vertex V3d(aPntAttach.X(), aPntAttach.Y(), aPntAttach.Z());
73   Prs3d_Root::CurrentGroup(aPresentation)->Marker(V3d);
74
75   // texte 
76   Prs3d_Text::Draw(aPresentation,LA->TextAspect(),aText,aPntOffset);
77 }
78
79
80
81 void DsgPrs_IdenticPresentation::Add( const Handle(Prs3d_Presentation)& aPresentation,
82                                       const Handle(Prs3d_Drawer)& aDrawer,
83                                       const TCollection_ExtendedString& aText,
84                                       const gp_Pnt& aFAttach,
85                                       const gp_Pnt& aSAttach,
86                                       const gp_Pnt& aPntOffset)
87 {
88   Handle(Prs3d_LengthAspect) LA = aDrawer->LengthAspect();
89   Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
90   
91   Graphic3d_Array1OfVertex V(1,2);
92   V(1).SetCoord(aFAttach.X(), aFAttach.Y(), aFAttach.Z());
93   V(2).SetCoord(aSAttach.X(), aSAttach.Y(), aSAttach.Z());
94
95   // trait de cote 
96   Prs3d_Root::CurrentGroup(aPresentation)->Polyline(V);
97
98   // trait joignant aPntOffset
99   Prs3d_Root::NewGroup(aPresentation);
100   Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
101   gp_Vec v1(aFAttach, aSAttach);
102   gp_Vec v2(aSAttach, aPntOffset);
103   V(1).SetCoord(aPntOffset.X(), aPntOffset.Y(), aPntOffset.Z());
104   if ( !v1.IsParallel(v2, Precision::Angular())) {
105     // on joint aPntOffset a son projete
106     gp_Lin ll(aFAttach, gp_Dir(v1));
107     gp_Pnt ProjPntOffset = ElCLib::Value(ElCLib::Parameter(ll,aPntOffset ), ll);
108     V(2).SetCoord(ProjPntOffset.X(), ProjPntOffset.Y(), ProjPntOffset.Z());
109   }
110   Prs3d_Root::CurrentGroup(aPresentation)->Polyline(V); 
111
112   // texte 
113   Prs3d_Text::Draw(aPresentation,LA->TextAspect(),aText,aPntOffset);
114 }
115
116
117
118 void DsgPrs_IdenticPresentation::Add(const Handle(Prs3d_Presentation)& aPresentation,
119                                      const Handle(Prs3d_Drawer)& aDrawer,
120                                      const TCollection_ExtendedString& aText,
121                                      const gp_Ax2& theAxe,
122                                      const gp_Pnt& aCenter,
123                                      const gp_Pnt& aFAttach,
124                                      const gp_Pnt& aSAttach,
125                                      const gp_Pnt& aPntOffset)
126 {
127   Handle(Prs3d_LengthAspect) LA = aDrawer->LengthAspect();
128   Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
129
130   gp_Ax2 ax = theAxe;
131   ax.SetLocation(aCenter);
132   Standard_Real rad = aCenter.Distance(aFAttach);
133   gp_Circ CC(ax,rad );
134   Standard_Real pFAttach =  ElCLib::Parameter(CC, aFAttach);
135   Standard_Real pSAttach =  ElCLib::Parameter(CC, aSAttach);
136   Standard_Real alpha = pSAttach - pFAttach;
137   if ( alpha < 0 ) alpha += 2 * M_PI;
138   Standard_Integer nb = (Standard_Integer )( 50. * alpha / M_PI);
139   Standard_Integer nbp = Max (4 , nb);
140   Graphic3d_Array1OfVertex V(1,nbp);
141   Standard_Real dteta = alpha/(nbp-1);
142   gp_Pnt ptcur;
143   for (Standard_Integer i = 1; i<=nbp; i++)
144     {
145       ptcur =  ElCLib::Value(pFAttach + dteta*(i-1),CC);
146       V(i).SetCoord(ptcur.X(),ptcur.Y(),ptcur.Z());
147     }
148
149   // trait de cote 
150   Prs3d_Root::CurrentGroup(aPresentation)->Polyline(V);
151   
152   // trait joignant aPntOffset
153   Prs3d_Root::NewGroup(aPresentation);
154   Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
155   Graphic3d_Array1OfVertex V2(1,2);
156   if ( Abs((aPntOffset.Distance(aCenter) - rad )) >= Precision::Confusion() ) {
157     gp_Pnt ProjPntOffset = ElCLib::Value(ElCLib::Parameter(CC,aPntOffset ), CC);
158     
159     V2(1).SetCoord(aPntOffset.X(), aPntOffset.Y(), aPntOffset.Z());
160     V2(2).SetCoord(ProjPntOffset.X(), ProjPntOffset.Y(), ProjPntOffset.Z());
161     Prs3d_Root::CurrentGroup(aPresentation)->Polyline(V2); 
162   }
163
164   // texte 
165   Prs3d_Text::Draw(aPresentation,LA->TextAspect(),aText,aPntOffset);
166 }
167
168 // jfa 16/10/2000
169 void DsgPrs_IdenticPresentation::Add(const Handle(Prs3d_Presentation)& aPresentation,
170                                      const Handle(Prs3d_Drawer)& aDrawer,
171                                      const TCollection_ExtendedString& aText,
172                                      const gp_Ax2& theAxe,
173                                      const gp_Pnt& aCenter,
174                                      const gp_Pnt& aFAttach,
175                                      const gp_Pnt& aSAttach,
176                                      const gp_Pnt& aPntOffset,
177                                      const gp_Pnt& aPntOnCirc)
178 {
179   Handle(Prs3d_LengthAspect) LA = aDrawer->LengthAspect();
180   Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
181
182   gp_Ax2 ax = theAxe;
183   ax.SetLocation(aCenter);
184   Standard_Real rad = aCenter.Distance(aFAttach);
185   gp_Circ CC(ax,rad );
186   Standard_Real pFAttach =  ElCLib::Parameter(CC, aFAttach);
187   Standard_Real pSAttach =  ElCLib::Parameter(CC, aSAttach);
188   Standard_Real alpha = pSAttach - pFAttach;
189   if ( alpha < 0 ) alpha += 2 * M_PI;
190   Standard_Integer nb = (Standard_Integer )( 50. * alpha / M_PI);
191   Standard_Integer nbp = Max (4 , nb);
192   Graphic3d_Array1OfVertex V(1,nbp);
193   Standard_Real dteta = alpha/(nbp-1);
194   gp_Pnt ptcur;
195   for (Standard_Integer i = 1; i<=nbp; i++)
196     {
197       ptcur =  ElCLib::Value(pFAttach + dteta*(i-1),CC);
198       V(i).SetCoord(ptcur.X(),ptcur.Y(),ptcur.Z());
199     }
200
201   // trait de cote 
202   Prs3d_Root::CurrentGroup(aPresentation)->Polyline(V);
203   
204   // trait joignant aPntOffset
205   Prs3d_Root::NewGroup(aPresentation);
206   Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
207   Graphic3d_Array1OfVertex V2(1,2);
208   if ( aPntOffset.Distance(aPntOnCirc) >= Precision::Confusion() )
209     {
210       V2(1).SetCoord(aPntOffset.X(), aPntOffset.Y(), aPntOffset.Z());
211       V2(2).SetCoord(aPntOnCirc.X(), aPntOnCirc.Y(), aPntOnCirc.Z());
212       Prs3d_Root::CurrentGroup(aPresentation)->Polyline(V2); 
213     }
214
215   // texte 
216   Prs3d_Text::Draw(aPresentation,LA->TextAspect(),aText,aPntOffset);
217 }
218 // jfa 16/10/2000 end
219
220 // jfa 10/10/2000
221 void DsgPrs_IdenticPresentation::Add(const Handle(Prs3d_Presentation)& aPresentation,
222                                      const Handle(Prs3d_Drawer)& aDrawer,
223                                      const TCollection_ExtendedString& aText,
224                                      const gp_Elips& anEllipse,
225                                      const gp_Pnt& aFAttach,
226                                      const gp_Pnt& aSAttach,
227                                      const gp_Pnt& aPntOffset,
228                                      const gp_Pnt& aPntOnElli)
229 {
230   Handle(Prs3d_LengthAspect) LA = aDrawer->LengthAspect();
231   Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
232
233   Standard_Real pFAttach =  ElCLib::Parameter(anEllipse, aFAttach);
234   Standard_Real pSAttach =  ElCLib::Parameter(anEllipse, aSAttach);
235   Standard_Real alpha = pSAttach - pFAttach;
236   if ( alpha < 0 ) alpha += 2 * M_PI;
237   Standard_Integer nb = (Standard_Integer)(50.0*alpha/M_PI);
238   Standard_Integer nbp = Max (4 , nb);
239   Graphic3d_Array1OfVertex V(1,nbp);
240   Standard_Real dteta = alpha/(nbp-1);
241   gp_Pnt ptcur;
242   for (Standard_Integer i = 1; i<=nbp; i++)
243     {
244       ptcur =  ElCLib::Value(pFAttach + dteta*(i-1),anEllipse);
245       V(i).SetCoord(ptcur.X(),ptcur.Y(),ptcur.Z());
246     }
247
248   // trait de cote 
249   Prs3d_Root::CurrentGroup(aPresentation)->Polyline(V);
250   
251   // trait joignant aPntOffset
252   Prs3d_Root::NewGroup(aPresentation);
253   Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
254   Graphic3d_Array1OfVertex V2(1,2);
255
256   if ( ! aPntOnElli.IsEqual(aPntOffset, Precision::Confusion()) )
257     {
258       V2(1).SetCoord(aPntOffset.X(), aPntOffset.Y(), aPntOffset.Z());
259       V2(2).SetCoord(aPntOnElli.X(), aPntOnElli.Y(), aPntOnElli.Z());
260       Prs3d_Root::CurrentGroup(aPresentation)->Polyline(V2); 
261     }
262
263   // texte 
264   Prs3d_Text::Draw(aPresentation,LA->TextAspect(),aText,aPntOffset);
265 }
266 // jfa 10/10/2000 end