84a27a5c4218abf856e042f3771f5e88de428bfa
[occt.git] / src / DsgPrs / DsgPrs_OffsetPresentation.cxx
1 // Created on: 1996-09-18
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
21
22 #include <DsgPrs_OffsetPresentation.ixx>
23
24 #include <gp_Lin.hxx>
25 #include <gp_Dir.hxx>
26
27 #include <ElCLib.hxx>
28
29 #include <gce_MakeLin.hxx>
30
31 #include <Graphic3d_Group.hxx>
32 #include <Graphic3d_Array1OfVertex.hxx>
33
34 #include <Prs3d_Arrow.hxx>
35 #include <Prs3d_ArrowAspect.hxx>
36 #include <Prs3d_LineAspect.hxx>
37 #include <Prs3d_LengthAspect.hxx>
38
39 #include <TCollection_AsciiString.hxx>
40
41 #include <Graphic3d_AspectLine3d.hxx>
42 #include <Graphic3d_AspectMarker3d.hxx>
43 #include <Graphic3d_Vertex.hxx>
44
45 #include <Aspect_TypeOfLine.hxx>
46 #include <Aspect_TypeOfMarker.hxx>
47 #include <Aspect_AspectMarker.hxx>
48
49 #include <Quantity_Color.hxx>
50
51 #include <Prs3d_Text.hxx>
52 #include <Precision.hxx>
53
54
55 void DsgPrs_OffsetPresentation::Add (const Handle(Prs3d_Presentation)& aPresentation,
56                                      const Handle(Prs3d_Drawer)& aDrawer,
57                                      const TCollection_ExtendedString& aText,
58                                      const gp_Pnt& AttachmentPoint1,
59                                      const gp_Pnt& AttachmentPoint2,
60                                      const gp_Dir& aDirection,
61                                      const gp_Dir& aDirection2,
62                                      const gp_Pnt& OffsetPoint) {
63
64
65   Handle(Prs3d_LengthAspect) LA = aDrawer->LengthAspect();
66   Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
67   gp_Lin L1 (AttachmentPoint1,aDirection);
68   gp_Lin L2 (AttachmentPoint2,aDirection2);
69   gp_Pnt Proj1 = ElCLib::Value(ElCLib::Parameter(L1,OffsetPoint),L1);
70   gp_Pnt Proj2 = ElCLib::Value(ElCLib::Parameter(L2,OffsetPoint),L2);
71   gp_Lin L3,L4;
72   Standard_Boolean DimNulle = Standard_False;
73   if (!Proj1.IsEqual(Proj2,Precision::Confusion()*100.)) {
74     L3 = gce_MakeLin(Proj1,Proj2);
75   }
76   else {
77     //cout<<"DsgPrs_OffsetPresentation Cote nulle"<<endl;
78     DimNulle = Standard_True;
79     L3 = gp_Lin(Proj1,aDirection); 
80     gp_Vec v4 (Proj1,OffsetPoint);
81     gp_Dir d4 (v4);
82     L4 = gp_Lin(Proj1,d4); // normale
83   }
84   Standard_Real parmin,parmax,parcur;
85   parmin = ElCLib::Parameter(L3,Proj1);
86   parmax = parmin;
87   parcur = ElCLib::Parameter(L3,Proj2);
88   Standard_Real dist = Abs(parmin-parcur);
89   if (parcur < parmin) parmin = parcur;
90   if (parcur > parmax) parmax = parcur;
91   parcur = ElCLib::Parameter(L3,OffsetPoint);
92   gp_Pnt offp = ElCLib::Value(parcur,L3);
93
94   Standard_Boolean outside = Standard_False;
95   if (parcur < parmin) {
96     parmin = parcur;
97     outside = Standard_True;
98   }
99   if (parcur > parmax) {
100     parmax = parcur;
101     outside = Standard_True;
102   }
103
104   gp_Pnt PointMin = ElCLib::Value(parmin,L3);
105   gp_Pnt PointMax = ElCLib::Value(parmax,L3);
106
107   Graphic3d_Array1OfVertex V(1,2);
108
109   Quantity_Length X,Y,Z;
110
111   PointMin.Coord(X,Y,Z);
112   V(1).SetCoord(X,Y,Z);
113
114   PointMax.Coord(X,Y,Z);
115   V(2).SetCoord(X,Y,Z);
116   // trait de cote : 1er groupe
117   Prs3d_Root::CurrentGroup(aPresentation)->Polyline(V);
118
119
120   if (DimNulle) {
121
122     Prs3d_Root::NewGroup(aPresentation);
123     Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
124     Prs3d_Arrow::Draw(aPresentation,offp,L4.Direction(),
125                       LA->Arrow1Aspect()->Angle(),
126                       LA->Arrow1Aspect()->Length());
127
128     Prs3d_Root::NewGroup(aPresentation);
129     Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
130     Prs3d_Arrow::Draw(aPresentation,offp,L4.Direction().Reversed(),
131                       LA->Arrow1Aspect()->Angle(),
132                       LA->Arrow1Aspect()->Length());
133   } else {
134     Prs3d_Root::NewGroup(aPresentation);
135     Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
136     
137     if (dist < (LA->Arrow1Aspect()->Length()+LA->Arrow2Aspect()->Length())) {
138       outside = Standard_True;
139     }
140     gp_Dir arrdir = L3.Direction().Reversed();
141     
142     if (outside) {
143       arrdir.Reverse();
144     }
145     // fleche 1 : 2eme groupe
146     Prs3d_Arrow::Draw(aPresentation,Proj1,arrdir,
147                       LA->Arrow1Aspect()->Angle(),
148                       LA->Arrow1Aspect()->Length());
149     
150     
151     Prs3d_Root::NewGroup(aPresentation);
152     Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
153     
154     // ball 1 : 3eme groupe
155     
156     Handle(Graphic3d_AspectMarker3d) MarkerAsp = new Graphic3d_AspectMarker3d();
157     MarkerAsp->SetType(Aspect_TOM_BALL);
158     MarkerAsp->SetScale(0.8);
159     Quantity_Color acolor;
160     Aspect_TypeOfLine atype;
161     Standard_Real awidth;
162     LA->LineAspect()->Aspect()->Values(acolor, atype, awidth);
163     MarkerAsp->SetColor(acolor);
164     Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(MarkerAsp);
165     Graphic3d_Vertex V3d(Proj2.X() ,Proj2.Y(), Proj2.Z());
166     Prs3d_Root::CurrentGroup(aPresentation)->Marker(V3d);
167     
168     Prs3d_Root::NewGroup(aPresentation);
169     
170     // texte : 4eme groupe
171     Prs3d_Text::Draw(aPresentation,LA->TextAspect(),aText,offp);
172   }
173
174   AttachmentPoint1.Coord(X,Y,Z);
175   V(1).SetCoord(X,Y,Z);
176   Proj1.Coord(X,Y,Z);
177   V(2).SetCoord(X,Y,Z);
178   
179   Prs3d_Root::NewGroup(aPresentation);
180   Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
181   // trait de rappel 1 : 5eme groupe
182   Prs3d_Root::CurrentGroup(aPresentation)->Polyline(V);
183   
184   AttachmentPoint2.Coord(X,Y,Z);
185   V(1).SetCoord(X,Y,Z);
186   Proj2.Coord(X,Y,Z);
187   V(2).SetCoord(X,Y,Z);
188
189   Prs3d_Root::NewGroup(aPresentation);
190   Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
191   // trait de rappel 2 : 6eme groupe
192   Prs3d_Root::CurrentGroup(aPresentation)->Polyline(V);
193   
194 }
195
196 void DsgPrs_OffsetPresentation::AddAxes (const Handle(Prs3d_Presentation)& aPresentation,
197                                          const Handle(Prs3d_Drawer)& aDrawer,
198                                          const TCollection_ExtendedString& aText,
199                                          const gp_Pnt& AttachmentPoint1,
200                                          const gp_Pnt& AttachmentPoint2,
201                                          const gp_Dir& aDirection,
202                                          const gp_Dir& aDirection2,
203                                          const gp_Pnt& OffsetPoint) {
204
205
206
207   gp_Lin L1 (AttachmentPoint1,aDirection);
208   gp_Pnt Proj1 = ElCLib::Value(ElCLib::Parameter(L1,OffsetPoint),L1);
209
210   gp_Lin L2 (AttachmentPoint2,aDirection);
211   gp_Pnt Proj2 = ElCLib::Value(ElCLib::Parameter(L2,OffsetPoint),L2);
212
213   Handle(Prs3d_LengthAspect) LA = aDrawer->LengthAspect();
214   Quantity_Color acolor;
215   Aspect_TypeOfLine atype;
216   Standard_Real awidth;
217   LA->LineAspect()->Aspect()->Values(acolor, atype, awidth);
218
219   Handle(Graphic3d_AspectLine3d) AxeAsp = new Graphic3d_AspectLine3d (acolor, atype, awidth);
220   AxeAsp->SetType( Aspect_TOL_DOTDASH);
221   Prs3d_Root::NewGroup(aPresentation);
222   Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(AxeAsp);
223
224   Graphic3d_Array1OfVertex V(1,2);
225   Quantity_Length X,Y,Z;
226
227   AttachmentPoint1.Coord(X,Y,Z);
228   V(1).SetCoord(X,Y,Z);
229
230   Proj1.Coord(X,Y,Z);
231   V(2).SetCoord(X,Y,Z);
232   // trait d'axe : 1er groupe
233   Prs3d_Root::CurrentGroup(aPresentation)->Polyline(V);
234
235   Prs3d_Root::NewGroup(aPresentation);
236   Handle(Graphic3d_AspectLine3d) Axe2Asp = new Graphic3d_AspectLine3d (acolor, atype, awidth);
237   Axe2Asp->SetType  ( Aspect_TOL_DOTDASH);
238   Axe2Asp->SetWidth ( 4.);
239   Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(Axe2Asp);
240
241   AttachmentPoint2.Coord(X,Y,Z);
242   V(1).SetCoord(X,Y,Z);
243
244   Proj2.Coord(X,Y,Z);
245   V(2).SetCoord(X,Y,Z);
246   // trait d'axe: 2eme groupe
247   Prs3d_Root::CurrentGroup(aPresentation)->Polyline(V);
248
249   // anneau : 3eme et 4eme groupes
250
251   Graphic3d_Vertex V3d(Proj2.X() ,Proj2.Y(), Proj2.Z());
252
253   Prs3d_Root::NewGroup(aPresentation);
254   Handle(Graphic3d_AspectMarker3d) MarkerAsp = new Graphic3d_AspectMarker3d();
255   MarkerAsp->SetType(Aspect_TOM_O);
256   MarkerAsp->SetScale(4.);
257   //MarkerAsp->SetColor(Quantity_Color(Quantity_NOC_RED));
258   MarkerAsp->SetColor(acolor);
259   Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(MarkerAsp);
260   Prs3d_Root::CurrentGroup(aPresentation)->Marker(V3d);
261
262   Prs3d_Root::NewGroup(aPresentation);
263   Handle(Graphic3d_AspectMarker3d) Marker2Asp = new Graphic3d_AspectMarker3d();
264   Marker2Asp->SetType(Aspect_TOM_O);
265   Marker2Asp->SetScale(2.);
266   //Marker2Asp->SetColor(Quantity_Color(Quantity_NOC_GREEN));
267   Marker2Asp->SetColor(acolor);
268   Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(Marker2Asp);
269   Prs3d_Root::CurrentGroup(aPresentation)->Marker(V3d);
270   
271 }