1 // Created on: 1995-11-28
2 // Created by: Jean-Pierre COMBE
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
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.
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.
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.
21 #include <DsgPrs_ParalPresentation.ixx>
25 #include <gce_MakeLin.hxx>
26 #include <Graphic3d_Group.hxx>
27 #include <Graphic3d_ArrayOfSegments.hxx>
28 #include <Prs3d_Arrow.hxx>
29 #include <Prs3d_ArrowAspect.hxx>
30 #include <Prs3d_LineAspect.hxx>
31 #include <Prs3d_DimensionAspect.hxx>
32 #include <TCollection_AsciiString.hxx>
33 #include <Graphic3d_AspectLine3d.hxx>
34 #include <Prs3d_Text.hxx>
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,
43 const gp_Pnt& OffsetPoint)
45 Handle(Prs3d_DimensionAspect) LA = aDrawer->DimensionAspect();
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);
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);
62 Standard_Boolean outside = Standard_False;
63 if (parcur < parmin) {
65 outside = Standard_True;
67 if (parcur > parmax) {
69 outside = Standard_True;
72 gp_Pnt PointMin = ElCLib::Value(parmin,L3);
73 gp_Pnt PointMax = ElCLib::Value(parmax,L3);
75 // processing of side : 1st group
76 Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(6);
77 aPrims->AddVertex(PointMin);
78 aPrims->AddVertex(PointMax);
80 Prs3d_Root::NewGroup(aPresentation);
81 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
83 if (dist < (LA->ArrowAspect()->Length()+LA->ArrowAspect()->Length()))
84 outside = Standard_True;
85 gp_Dir arrdir = L3.Direction().Reversed();
89 // arrow 1 : 2nd group
90 Prs3d_Arrow::Draw(aPresentation,Proj1,arrdir,LA->ArrowAspect()->Angle(),LA->ArrowAspect()->Length());
92 Prs3d_Root::NewGroup(aPresentation);
93 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
95 // arrow 2 : 3rd group
96 Prs3d_Arrow::Draw(aPresentation,Proj2,arrdir.Reversed(),LA->ArrowAspect()->Angle(),LA->ArrowAspect()->Length());
98 Prs3d_Root::NewGroup(aPresentation);
101 Prs3d_Text::Draw(aPresentation,LA->TextAspect(),aText,offp);
103 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
105 // processing of call 1 : 5th group
106 aPrims->AddVertex(AttachmentPoint1);
107 aPrims->AddVertex(Proj1);
109 // processing of call 2 : 6th group
110 aPrims->AddVertex(AttachmentPoint2);
111 aPrims->AddVertex(Proj2);
113 Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims);
117 //==========================================================================
118 // function : DsgPrs_ParalPresentation::Add
119 // purpose : it is possible to choose the symbol of extremities of the face (arrow, point...)
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,
128 const DsgPrs_ArrowSide ArrowPrs)
130 Handle(Prs3d_DimensionAspect) LA = aDrawer->DimensionAspect();
131 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
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);
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);
148 Standard_Boolean outside = Standard_False;
149 if (parcur < parmin) {
151 outside = Standard_True;
153 if (parcur > parmax) {
155 outside = Standard_True;
158 gp_Pnt PointMin = ElCLib::Value(parmin,L3);
159 gp_Pnt PointMax = ElCLib::Value(parmax,L3);
161 // processing of face
162 Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(6);
163 aPrims->AddVertex(PointMin);
164 aPrims->AddVertex(PointMax);
166 if (dist < (LA->ArrowAspect()->Length()+LA->ArrowAspect()->Length()))
167 outside = Standard_True;
168 gp_Dir arrdir = L3.Direction().Reversed();
172 // processing of call 1
173 aPrims->AddVertex(AttachmentPoint1);
174 aPrims->AddVertex(Proj1);
176 // processing of call 2
177 aPrims->AddVertex(AttachmentPoint2);
178 aPrims->AddVertex(Proj2);
180 Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims);
183 Prs3d_Text::Draw(aPresentation,LA->TextAspect(),aText,offp);
186 DsgPrs::ComputeSymbol(aPresentation,LA,Proj1,Proj2,arrdir,arrdir.Reversed(),ArrowPrs);