b311480e |
1 | // Created on: 1995-11-28 |
2 | // Created by: Jean-Pierre COMBE |
3 | // Copyright (c) 1995-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 | |
42cf5bc1 |
17 | |
18 | #include <DsgPrs.hxx> |
19 | #include <DsgPrs_ParalPresentation.hxx> |
7fd59977 |
20 | #include <ElCLib.hxx> |
21 | #include <gce_MakeLin.hxx> |
42cf5bc1 |
22 | #include <gp_Dir.hxx> |
23 | #include <gp_Lin.hxx> |
24 | #include <gp_Pnt.hxx> |
b8ddfc2f |
25 | #include <Graphic3d_ArrayOfSegments.hxx> |
42cf5bc1 |
26 | #include <Graphic3d_AspectLine3d.hxx> |
27 | #include <Graphic3d_Group.hxx> |
7fd59977 |
28 | #include <Prs3d_Arrow.hxx> |
29 | #include <Prs3d_ArrowAspect.hxx> |
a6eb515f |
30 | #include <Prs3d_DimensionAspect.hxx> |
42cf5bc1 |
31 | #include <Prs3d_LineAspect.hxx> |
32 | #include <Prs3d_Presentation.hxx> |
7fd59977 |
33 | #include <Prs3d_Text.hxx> |
42cf5bc1 |
34 | #include <TCollection_AsciiString.hxx> |
35 | #include <TCollection_ExtendedString.hxx> |
7fd59977 |
36 | |
37 | void DsgPrs_ParalPresentation::Add (const Handle(Prs3d_Presentation)& aPresentation, |
38 | const Handle(Prs3d_Drawer)& aDrawer, |
39 | const TCollection_ExtendedString& aText, |
40 | const gp_Pnt& AttachmentPoint1, |
41 | const gp_Pnt& AttachmentPoint2, |
42 | const gp_Dir& aDirection, |
b8ddfc2f |
43 | const gp_Pnt& OffsetPoint) |
44 | { |
a6eb515f |
45 | Handle(Prs3d_DimensionAspect) LA = aDrawer->DimensionAspect(); |
7fd59977 |
46 | Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect()); |
47 | gp_Lin L1 (AttachmentPoint1,aDirection); |
48 | gp_Lin L2 (AttachmentPoint2,aDirection); |
49 | gp_Pnt Proj1 = ElCLib::Value(ElCLib::Parameter(L1,OffsetPoint),L1); |
50 | gp_Pnt Proj2 = ElCLib::Value(ElCLib::Parameter(L2,OffsetPoint),L2); |
51 | gp_Lin L3 = gce_MakeLin(Proj1,Proj2); |
52 | Standard_Real parmin,parmax,parcur; |
53 | parmin = ElCLib::Parameter(L3,Proj1); |
54 | parmax = parmin; |
55 | parcur = ElCLib::Parameter(L3,Proj2); |
56 | Standard_Real dist = Abs(parmin-parcur); |
57 | if (parcur < parmin) parmin = parcur; |
58 | if (parcur > parmax) parmax = parcur; |
59 | parcur = ElCLib::Parameter(L3,OffsetPoint); |
60 | gp_Pnt offp = ElCLib::Value(parcur,L3); |
61 | |
62 | Standard_Boolean outside = Standard_False; |
63 | if (parcur < parmin) { |
64 | parmin = parcur; |
65 | outside = Standard_True; |
66 | } |
67 | if (parcur > parmax) { |
68 | parmax = parcur; |
69 | outside = Standard_True; |
70 | } |
71 | |
72 | gp_Pnt PointMin = ElCLib::Value(parmin,L3); |
73 | gp_Pnt PointMax = ElCLib::Value(parmax,L3); |
74 | |
81bba717 |
75 | // processing of side : 1st group |
b8ddfc2f |
76 | Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(6); |
77 | aPrims->AddVertex(PointMin); |
78 | aPrims->AddVertex(PointMax); |
7fd59977 |
79 | |
80 | Prs3d_Root::NewGroup(aPresentation); |
81 | Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect()); |
82 | |
a6eb515f |
83 | if (dist < (LA->ArrowAspect()->Length()+LA->ArrowAspect()->Length())) |
7fd59977 |
84 | outside = Standard_True; |
7fd59977 |
85 | gp_Dir arrdir = L3.Direction().Reversed(); |
b8ddfc2f |
86 | if (outside) |
7fd59977 |
87 | arrdir.Reverse(); |
b8ddfc2f |
88 | |
81bba717 |
89 | // arrow 1 : 2nd group |
a6eb515f |
90 | Prs3d_Arrow::Draw(aPresentation,Proj1,arrdir,LA->ArrowAspect()->Angle(),LA->ArrowAspect()->Length()); |
7fd59977 |
91 | |
92 | Prs3d_Root::NewGroup(aPresentation); |
93 | Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect()); |
94 | |
81bba717 |
95 | // arrow 2 : 3rd group |
a6eb515f |
96 | Prs3d_Arrow::Draw(aPresentation,Proj2,arrdir.Reversed(),LA->ArrowAspect()->Angle(),LA->ArrowAspect()->Length()); |
7fd59977 |
97 | |
98 | Prs3d_Root::NewGroup(aPresentation); |
99 | |
81bba717 |
100 | // text : 4th group |
7fd59977 |
101 | Prs3d_Text::Draw(aPresentation,LA->TextAspect(),aText,offp); |
7fd59977 |
102 | |
7fd59977 |
103 | Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect()); |
b8ddfc2f |
104 | |
81bba717 |
105 | // processing of call 1 : 5th group |
b8ddfc2f |
106 | aPrims->AddVertex(AttachmentPoint1); |
107 | aPrims->AddVertex(Proj1); |
7fd59977 |
108 | |
81bba717 |
109 | // processing of call 2 : 6th group |
b8ddfc2f |
110 | aPrims->AddVertex(AttachmentPoint2); |
111 | aPrims->AddVertex(Proj2); |
112 | |
113 | Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims); |
7fd59977 |
114 | } |
115 | |
116 | |
117 | //========================================================================== |
118 | // function : DsgPrs_ParalPresentation::Add |
81bba717 |
119 | // purpose : it is possible to choose the symbol of extremities of the face (arrow, point...) |
7fd59977 |
120 | //========================================================================== |
121 | void DsgPrs_ParalPresentation::Add (const Handle(Prs3d_Presentation)& aPresentation, |
122 | const Handle(Prs3d_Drawer)& aDrawer, |
123 | const TCollection_ExtendedString& aText, |
124 | const gp_Pnt& AttachmentPoint1, |
125 | const gp_Pnt& AttachmentPoint2, |
126 | const gp_Dir& aDirection, |
127 | const gp_Pnt& OffsetPoint, |
b8ddfc2f |
128 | const DsgPrs_ArrowSide ArrowPrs) |
129 | { |
a6eb515f |
130 | Handle(Prs3d_DimensionAspect) LA = aDrawer->DimensionAspect(); |
7fd59977 |
131 | Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect()); |
132 | |
133 | gp_Lin L1 (AttachmentPoint1,aDirection); |
134 | gp_Lin L2 (AttachmentPoint2,aDirection); |
135 | gp_Pnt Proj1 = ElCLib::Value(ElCLib::Parameter(L1,OffsetPoint),L1); |
136 | gp_Pnt Proj2 = ElCLib::Value(ElCLib::Parameter(L2,OffsetPoint),L2); |
137 | gp_Lin L3 = gce_MakeLin(Proj1,Proj2); |
138 | Standard_Real parmin,parmax,parcur; |
139 | parmin = ElCLib::Parameter(L3,Proj1); |
140 | parmax = parmin; |
141 | parcur = ElCLib::Parameter(L3,Proj2); |
142 | Standard_Real dist = Abs(parmin-parcur); |
143 | if (parcur < parmin) parmin = parcur; |
144 | if (parcur > parmax) parmax = parcur; |
145 | parcur = ElCLib::Parameter(L3,OffsetPoint); |
146 | gp_Pnt offp = ElCLib::Value(parcur,L3); |
147 | |
148 | Standard_Boolean outside = Standard_False; |
149 | if (parcur < parmin) { |
150 | parmin = parcur; |
151 | outside = Standard_True; |
152 | } |
153 | if (parcur > parmax) { |
154 | parmax = parcur; |
155 | outside = Standard_True; |
156 | } |
157 | |
158 | gp_Pnt PointMin = ElCLib::Value(parmin,L3); |
159 | gp_Pnt PointMax = ElCLib::Value(parmax,L3); |
160 | |
81bba717 |
161 | // processing of face |
b8ddfc2f |
162 | Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(6); |
163 | aPrims->AddVertex(PointMin); |
164 | aPrims->AddVertex(PointMax); |
7fd59977 |
165 | |
a6eb515f |
166 | if (dist < (LA->ArrowAspect()->Length()+LA->ArrowAspect()->Length())) |
7fd59977 |
167 | outside = Standard_True; |
7fd59977 |
168 | gp_Dir arrdir = L3.Direction().Reversed(); |
b8ddfc2f |
169 | if (outside) |
7fd59977 |
170 | arrdir.Reverse(); |
7fd59977 |
171 | |
81bba717 |
172 | // processing of call 1 |
b8ddfc2f |
173 | aPrims->AddVertex(AttachmentPoint1); |
174 | aPrims->AddVertex(Proj1); |
7fd59977 |
175 | |
b8ddfc2f |
176 | // processing of call 2 |
177 | aPrims->AddVertex(AttachmentPoint2); |
178 | aPrims->AddVertex(Proj2); |
179 | |
180 | Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims); |
7fd59977 |
181 | |
81bba717 |
182 | // text |
7fd59977 |
183 | Prs3d_Text::Draw(aPresentation,LA->TextAspect(),aText,offp); |
184 | |
81bba717 |
185 | //arrows |
7fd59977 |
186 | DsgPrs::ComputeSymbol(aPresentation,LA,Proj1,Proj2,arrdir,arrdir.Reversed(),ArrowPrs); |
7fd59977 |
187 | } |