b311480e |
1 | // Created on: 1996-09-18 |
2 | // Created by: Jacques MINOT |
3 | // Copyright (c) 1996-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
12 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
b311480e |
16 | |
7fd59977 |
17 | |
42cf5bc1 |
18 | #include <Aspect_AspectMarker.hxx> |
19 | #include <Aspect_TypeOfLine.hxx> |
20 | #include <Aspect_TypeOfMarker.hxx> |
21 | #include <DsgPrs_OffsetPresentation.hxx> |
7fd59977 |
22 | #include <ElCLib.hxx> |
7fd59977 |
23 | #include <gce_MakeLin.hxx> |
42cf5bc1 |
24 | #include <gp_Dir.hxx> |
25 | #include <gp_Lin.hxx> |
26 | #include <gp_Pnt.hxx> |
a577aaab |
27 | #include <Graphic3d_ArrayOfPoints.hxx> |
42cf5bc1 |
28 | #include <Graphic3d_ArrayOfSegments.hxx> |
7fd59977 |
29 | #include <Graphic3d_AspectLine3d.hxx> |
30 | #include <Graphic3d_AspectMarker3d.hxx> |
42cf5bc1 |
31 | #include <Graphic3d_Group.hxx> |
7fd59977 |
32 | #include <Graphic3d_Vertex.hxx> |
7fd59977 |
33 | #include <Precision.hxx> |
42cf5bc1 |
34 | #include <Prs3d_Arrow.hxx> |
35 | #include <Prs3d_ArrowAspect.hxx> |
36 | #include <Prs3d_DimensionAspect.hxx> |
37 | #include <Prs3d_LineAspect.hxx> |
38 | #include <Prs3d_Presentation.hxx> |
39 | #include <Prs3d_Text.hxx> |
40 | #include <Quantity_Color.hxx> |
41 | #include <TCollection_AsciiString.hxx> |
42 | #include <TCollection_ExtendedString.hxx> |
7fd59977 |
43 | |
44 | void DsgPrs_OffsetPresentation::Add (const Handle(Prs3d_Presentation)& aPresentation, |
45 | const Handle(Prs3d_Drawer)& aDrawer, |
46 | const TCollection_ExtendedString& aText, |
47 | const gp_Pnt& AttachmentPoint1, |
48 | const gp_Pnt& AttachmentPoint2, |
49 | const gp_Dir& aDirection, |
50 | const gp_Dir& aDirection2, |
b8ddfc2f |
51 | const gp_Pnt& OffsetPoint) |
52 | { |
a6eb515f |
53 | Handle(Prs3d_DimensionAspect) LA = aDrawer->DimensionAspect(); |
7fd59977 |
54 | Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect()); |
b8ddfc2f |
55 | |
7fd59977 |
56 | gp_Lin L1 (AttachmentPoint1,aDirection); |
57 | gp_Lin L2 (AttachmentPoint2,aDirection2); |
58 | gp_Pnt Proj1 = ElCLib::Value(ElCLib::Parameter(L1,OffsetPoint),L1); |
59 | gp_Pnt Proj2 = ElCLib::Value(ElCLib::Parameter(L2,OffsetPoint),L2); |
60 | gp_Lin L3,L4; |
61 | Standard_Boolean DimNulle = Standard_False; |
62 | if (!Proj1.IsEqual(Proj2,Precision::Confusion()*100.)) { |
63 | L3 = gce_MakeLin(Proj1,Proj2); |
64 | } |
65 | else { |
66 | //cout<<"DsgPrs_OffsetPresentation Cote nulle"<<endl; |
67 | DimNulle = Standard_True; |
68 | L3 = gp_Lin(Proj1,aDirection); |
69 | gp_Vec v4 (Proj1,OffsetPoint); |
70 | gp_Dir d4 (v4); |
71 | L4 = gp_Lin(Proj1,d4); // normale |
72 | } |
73 | Standard_Real parmin,parmax,parcur; |
74 | parmin = ElCLib::Parameter(L3,Proj1); |
75 | parmax = parmin; |
76 | parcur = ElCLib::Parameter(L3,Proj2); |
77 | Standard_Real dist = Abs(parmin-parcur); |
78 | if (parcur < parmin) parmin = parcur; |
79 | if (parcur > parmax) parmax = parcur; |
80 | parcur = ElCLib::Parameter(L3,OffsetPoint); |
81 | gp_Pnt offp = ElCLib::Value(parcur,L3); |
82 | |
83 | Standard_Boolean outside = Standard_False; |
84 | if (parcur < parmin) { |
85 | parmin = parcur; |
86 | outside = Standard_True; |
87 | } |
88 | if (parcur > parmax) { |
89 | parmax = parcur; |
90 | outside = Standard_True; |
91 | } |
92 | |
93 | gp_Pnt PointMin = ElCLib::Value(parmin,L3); |
94 | gp_Pnt PointMax = ElCLib::Value(parmax,L3); |
95 | |
7fd59977 |
96 | // trait de cote : 1er groupe |
b8ddfc2f |
97 | Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(6); |
98 | aPrims->AddVertex(PointMin); |
99 | aPrims->AddVertex(PointMax); |
7fd59977 |
100 | |
b8ddfc2f |
101 | Prs3d_Root::NewGroup(aPresentation); |
102 | Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect()); |
7fd59977 |
103 | |
b8ddfc2f |
104 | if (DimNulle) |
105 | { |
a6eb515f |
106 | Prs3d_Arrow::Draw(aPresentation,offp,L4.Direction(),LA->ArrowAspect()->Angle(),LA->ArrowAspect()->Length()); |
107 | Prs3d_Arrow::Draw(aPresentation,offp,L4.Direction().Reversed(),LA->ArrowAspect()->Angle(),LA->ArrowAspect()->Length()); |
b8ddfc2f |
108 | } |
109 | else |
110 | { |
a6eb515f |
111 | if (dist < (LA->ArrowAspect()->Length()+LA->ArrowAspect()->Length())) |
7fd59977 |
112 | outside = Standard_True; |
7fd59977 |
113 | gp_Dir arrdir = L3.Direction().Reversed(); |
b8ddfc2f |
114 | if (outside) |
7fd59977 |
115 | arrdir.Reverse(); |
b8ddfc2f |
116 | |
7fd59977 |
117 | // fleche 1 : 2eme groupe |
a6eb515f |
118 | Prs3d_Arrow::Draw(aPresentation,Proj1,arrdir,LA->ArrowAspect()->Angle(),LA->ArrowAspect()->Length()); |
b8ddfc2f |
119 | |
7fd59977 |
120 | Prs3d_Root::NewGroup(aPresentation); |
121 | Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect()); |
122 | |
123 | // ball 1 : 3eme groupe |
a577aaab |
124 | Quantity_Color aColor; |
125 | Aspect_TypeOfLine aType; |
126 | Standard_Real aWidth; |
127 | LA->LineAspect()->Aspect()->Values (aColor, aType, aWidth); |
128 | Handle(Graphic3d_AspectMarker3d) aMarkerAsp = new Graphic3d_AspectMarker3d (Aspect_TOM_O, aColor, 1.0); |
129 | Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect (aMarkerAsp); |
130 | Handle(Graphic3d_ArrayOfPoints) anArrayOfPoints = new Graphic3d_ArrayOfPoints (1); |
131 | anArrayOfPoints->AddVertex (Proj2.X(), Proj2.Y(), Proj2.Z()); |
132 | Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray (anArrayOfPoints); |
133 | |
7fd59977 |
134 | Prs3d_Root::NewGroup(aPresentation); |
a577aaab |
135 | |
7fd59977 |
136 | // texte : 4eme groupe |
137 | Prs3d_Text::Draw(aPresentation,LA->TextAspect(),aText,offp); |
138 | } |
139 | |
7fd59977 |
140 | Prs3d_Root::NewGroup(aPresentation); |
141 | Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect()); |
b8ddfc2f |
142 | |
7fd59977 |
143 | // trait de rappel 1 : 5eme groupe |
b8ddfc2f |
144 | aPrims->AddVertex(AttachmentPoint1); |
145 | aPrims->AddVertex(Proj1); |
7fd59977 |
146 | |
7fd59977 |
147 | // trait de rappel 2 : 6eme groupe |
b8ddfc2f |
148 | aPrims->AddVertex(AttachmentPoint2); |
149 | aPrims->AddVertex(Proj2); |
150 | |
151 | Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims); |
7fd59977 |
152 | } |
153 | |
154 | void DsgPrs_OffsetPresentation::AddAxes (const Handle(Prs3d_Presentation)& aPresentation, |
155 | const Handle(Prs3d_Drawer)& aDrawer, |
35e08fe8 |
156 | const TCollection_ExtendedString& /*aText*/, |
7fd59977 |
157 | const gp_Pnt& AttachmentPoint1, |
158 | const gp_Pnt& AttachmentPoint2, |
159 | const gp_Dir& aDirection, |
35e08fe8 |
160 | const gp_Dir& /*aDirection2*/, |
b8ddfc2f |
161 | const gp_Pnt& OffsetPoint) |
162 | { |
7fd59977 |
163 | gp_Lin L1 (AttachmentPoint1,aDirection); |
164 | gp_Pnt Proj1 = ElCLib::Value(ElCLib::Parameter(L1,OffsetPoint),L1); |
165 | |
166 | gp_Lin L2 (AttachmentPoint2,aDirection); |
167 | gp_Pnt Proj2 = ElCLib::Value(ElCLib::Parameter(L2,OffsetPoint),L2); |
168 | |
a6eb515f |
169 | Handle(Prs3d_DimensionAspect) LA = aDrawer->DimensionAspect(); |
7fd59977 |
170 | Quantity_Color acolor; |
171 | Aspect_TypeOfLine atype; |
172 | Standard_Real awidth; |
173 | LA->LineAspect()->Aspect()->Values(acolor, atype, awidth); |
174 | |
175 | Handle(Graphic3d_AspectLine3d) AxeAsp = new Graphic3d_AspectLine3d (acolor, atype, awidth); |
176 | AxeAsp->SetType( Aspect_TOL_DOTDASH); |
177 | Prs3d_Root::NewGroup(aPresentation); |
178 | Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(AxeAsp); |
179 | |
7fd59977 |
180 | // trait d'axe : 1er groupe |
b8ddfc2f |
181 | Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(2); |
182 | aPrims->AddVertex(AttachmentPoint1); |
183 | aPrims->AddVertex(Proj1); |
184 | Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims); |
7fd59977 |
185 | |
186 | Prs3d_Root::NewGroup(aPresentation); |
b8ddfc2f |
187 | |
7fd59977 |
188 | Handle(Graphic3d_AspectLine3d) Axe2Asp = new Graphic3d_AspectLine3d (acolor, atype, awidth); |
189 | Axe2Asp->SetType ( Aspect_TOL_DOTDASH); |
190 | Axe2Asp->SetWidth ( 4.); |
191 | Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(Axe2Asp); |
192 | |
7fd59977 |
193 | // trait d'axe: 2eme groupe |
b8ddfc2f |
194 | aPrims = new Graphic3d_ArrayOfSegments(2); |
195 | aPrims->AddVertex(AttachmentPoint2); |
196 | aPrims->AddVertex(Proj2); |
197 | Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims); |
7fd59977 |
198 | |
199 | // anneau : 3eme et 4eme groupes |
a577aaab |
200 | Handle(Graphic3d_ArrayOfPoints) anArrayOfPoints = new Graphic3d_ArrayOfPoints (1); |
201 | anArrayOfPoints->AddVertex (Proj2.X(), Proj2.Y(), Proj2.Z()); |
7fd59977 |
202 | |
203 | Prs3d_Root::NewGroup(aPresentation); |
204 | Handle(Graphic3d_AspectMarker3d) MarkerAsp = new Graphic3d_AspectMarker3d(); |
205 | MarkerAsp->SetType(Aspect_TOM_O); |
206 | MarkerAsp->SetScale(4.); |
207 | //MarkerAsp->SetColor(Quantity_Color(Quantity_NOC_RED)); |
208 | MarkerAsp->SetColor(acolor); |
209 | Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(MarkerAsp); |
a577aaab |
210 | Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray (anArrayOfPoints); |
7fd59977 |
211 | |
212 | Prs3d_Root::NewGroup(aPresentation); |
213 | Handle(Graphic3d_AspectMarker3d) Marker2Asp = new Graphic3d_AspectMarker3d(); |
214 | Marker2Asp->SetType(Aspect_TOM_O); |
215 | Marker2Asp->SetScale(2.); |
216 | //Marker2Asp->SetColor(Quantity_Color(Quantity_NOC_GREEN)); |
217 | Marker2Asp->SetColor(acolor); |
218 | Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(Marker2Asp); |
a577aaab |
219 | Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray (anArrayOfPoints); |
7fd59977 |
220 | } |