0030480: Visualization - Clear of Select3D_SensitiveGroup does not update internal...
[occt.git] / src / DsgPrs / DsgPrs_OffsetPresentation.cxx
CommitLineData
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
42cf5bc1 17#include <DsgPrs_OffsetPresentation.hxx>
b6472664 18
7fd59977 19#include <ElCLib.hxx>
7fd59977 20#include <gce_MakeLin.hxx>
42cf5bc1 21#include <gp_Dir.hxx>
22#include <gp_Lin.hxx>
23#include <gp_Pnt.hxx>
a577aaab 24#include <Graphic3d_ArrayOfPoints.hxx>
42cf5bc1 25#include <Graphic3d_ArrayOfSegments.hxx>
7fd59977 26#include <Graphic3d_AspectLine3d.hxx>
27#include <Graphic3d_AspectMarker3d.hxx>
42cf5bc1 28#include <Graphic3d_Group.hxx>
7fd59977 29#include <Precision.hxx>
42cf5bc1 30#include <Prs3d_Arrow.hxx>
31#include <Prs3d_ArrowAspect.hxx>
32#include <Prs3d_DimensionAspect.hxx>
33#include <Prs3d_LineAspect.hxx>
34#include <Prs3d_Presentation.hxx>
35#include <Prs3d_Text.hxx>
42cf5bc1 36#include <TCollection_AsciiString.hxx>
37#include <TCollection_ExtendedString.hxx>
7fd59977 38
39void DsgPrs_OffsetPresentation::Add (const Handle(Prs3d_Presentation)& aPresentation,
40 const Handle(Prs3d_Drawer)& aDrawer,
41 const TCollection_ExtendedString& aText,
42 const gp_Pnt& AttachmentPoint1,
43 const gp_Pnt& AttachmentPoint2,
44 const gp_Dir& aDirection,
45 const gp_Dir& aDirection2,
b8ddfc2f 46 const gp_Pnt& OffsetPoint)
47{
a6eb515f 48 Handle(Prs3d_DimensionAspect) LA = aDrawer->DimensionAspect();
7fd59977 49 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
b8ddfc2f 50
7fd59977 51 gp_Lin L1 (AttachmentPoint1,aDirection);
52 gp_Lin L2 (AttachmentPoint2,aDirection2);
53 gp_Pnt Proj1 = ElCLib::Value(ElCLib::Parameter(L1,OffsetPoint),L1);
54 gp_Pnt Proj2 = ElCLib::Value(ElCLib::Parameter(L2,OffsetPoint),L2);
55 gp_Lin L3,L4;
56 Standard_Boolean DimNulle = Standard_False;
57 if (!Proj1.IsEqual(Proj2,Precision::Confusion()*100.)) {
58 L3 = gce_MakeLin(Proj1,Proj2);
59 }
60 else {
61 //cout<<"DsgPrs_OffsetPresentation Cote nulle"<<endl;
62 DimNulle = Standard_True;
63 L3 = gp_Lin(Proj1,aDirection);
64 gp_Vec v4 (Proj1,OffsetPoint);
65 gp_Dir d4 (v4);
66 L4 = gp_Lin(Proj1,d4); // normale
67 }
68 Standard_Real parmin,parmax,parcur;
69 parmin = ElCLib::Parameter(L3,Proj1);
70 parmax = parmin;
71 parcur = ElCLib::Parameter(L3,Proj2);
72 Standard_Real dist = Abs(parmin-parcur);
73 if (parcur < parmin) parmin = parcur;
74 if (parcur > parmax) parmax = parcur;
75 parcur = ElCLib::Parameter(L3,OffsetPoint);
76 gp_Pnt offp = ElCLib::Value(parcur,L3);
77
78 Standard_Boolean outside = Standard_False;
79 if (parcur < parmin) {
80 parmin = parcur;
81 outside = Standard_True;
82 }
83 if (parcur > parmax) {
84 parmax = parcur;
85 outside = Standard_True;
86 }
87
88 gp_Pnt PointMin = ElCLib::Value(parmin,L3);
89 gp_Pnt PointMax = ElCLib::Value(parmax,L3);
90
7fd59977 91 // trait de cote : 1er groupe
b8ddfc2f 92 Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(6);
93 aPrims->AddVertex(PointMin);
94 aPrims->AddVertex(PointMax);
7fd59977 95
b8ddfc2f 96 Prs3d_Root::NewGroup(aPresentation);
97 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
7fd59977 98
b8ddfc2f 99 if (DimNulle)
100 {
4ad142d9 101 Prs3d_Arrow::Draw (Prs3d_Root::CurrentGroup (aPresentation), offp, L4.Direction(), LA->ArrowAspect()->Angle(), LA->ArrowAspect()->Length());
102 Prs3d_Arrow::Draw (Prs3d_Root::CurrentGroup (aPresentation), offp, L4.Direction().Reversed(), LA->ArrowAspect()->Angle(), LA->ArrowAspect()->Length());
b8ddfc2f 103 }
104 else
105 {
a6eb515f 106 if (dist < (LA->ArrowAspect()->Length()+LA->ArrowAspect()->Length()))
7fd59977 107 outside = Standard_True;
7fd59977 108 gp_Dir arrdir = L3.Direction().Reversed();
b8ddfc2f 109 if (outside)
7fd59977 110 arrdir.Reverse();
b8ddfc2f 111
7fd59977 112 // fleche 1 : 2eme groupe
4ad142d9 113 Prs3d_Arrow::Draw (Prs3d_Root::CurrentGroup (aPresentation), Proj1, arrdir, LA->ArrowAspect()->Angle(), LA->ArrowAspect()->Length());
b8ddfc2f 114
7fd59977 115 Prs3d_Root::NewGroup(aPresentation);
116 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
117
118 // ball 1 : 3eme groupe
b6472664 119 Quantity_Color aColor = LA->LineAspect()->Aspect()->Color();
a577aaab 120 Handle(Graphic3d_AspectMarker3d) aMarkerAsp = new Graphic3d_AspectMarker3d (Aspect_TOM_O, aColor, 1.0);
121 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect (aMarkerAsp);
122 Handle(Graphic3d_ArrayOfPoints) anArrayOfPoints = new Graphic3d_ArrayOfPoints (1);
123 anArrayOfPoints->AddVertex (Proj2.X(), Proj2.Y(), Proj2.Z());
124 Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray (anArrayOfPoints);
125
7fd59977 126 Prs3d_Root::NewGroup(aPresentation);
a577aaab 127
7fd59977 128 // texte : 4eme groupe
4ad142d9 129 Prs3d_Text::Draw (Prs3d_Root::CurrentGroup (aPresentation), LA->TextAspect(), aText, offp);
7fd59977 130 }
131
7fd59977 132 Prs3d_Root::NewGroup(aPresentation);
133 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
b8ddfc2f 134
7fd59977 135 // trait de rappel 1 : 5eme groupe
b8ddfc2f 136 aPrims->AddVertex(AttachmentPoint1);
137 aPrims->AddVertex(Proj1);
7fd59977 138
7fd59977 139 // trait de rappel 2 : 6eme groupe
b8ddfc2f 140 aPrims->AddVertex(AttachmentPoint2);
141 aPrims->AddVertex(Proj2);
142
143 Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims);
7fd59977 144}
145
146void DsgPrs_OffsetPresentation::AddAxes (const Handle(Prs3d_Presentation)& aPresentation,
147 const Handle(Prs3d_Drawer)& aDrawer,
35e08fe8 148 const TCollection_ExtendedString& /*aText*/,
7fd59977 149 const gp_Pnt& AttachmentPoint1,
150 const gp_Pnt& AttachmentPoint2,
151 const gp_Dir& aDirection,
35e08fe8 152 const gp_Dir& /*aDirection2*/,
b8ddfc2f 153 const gp_Pnt& OffsetPoint)
154{
7fd59977 155 gp_Lin L1 (AttachmentPoint1,aDirection);
156 gp_Pnt Proj1 = ElCLib::Value(ElCLib::Parameter(L1,OffsetPoint),L1);
157
158 gp_Lin L2 (AttachmentPoint2,aDirection);
159 gp_Pnt Proj2 = ElCLib::Value(ElCLib::Parameter(L2,OffsetPoint),L2);
160
a6eb515f 161 Handle(Prs3d_DimensionAspect) LA = aDrawer->DimensionAspect();
b6472664 162 Quantity_Color acolor = LA->LineAspect()->Aspect()->Color();
163 Aspect_TypeOfLine atype = LA->LineAspect()->Aspect()->Type();
164 Standard_Real awidth = LA->LineAspect()->Aspect()->Width();
7fd59977 165
166 Handle(Graphic3d_AspectLine3d) AxeAsp = new Graphic3d_AspectLine3d (acolor, atype, awidth);
167 AxeAsp->SetType( Aspect_TOL_DOTDASH);
168 Prs3d_Root::NewGroup(aPresentation);
169 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(AxeAsp);
170
7fd59977 171 // trait d'axe : 1er groupe
b8ddfc2f 172 Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(2);
173 aPrims->AddVertex(AttachmentPoint1);
174 aPrims->AddVertex(Proj1);
175 Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims);
7fd59977 176
177 Prs3d_Root::NewGroup(aPresentation);
b8ddfc2f 178
7fd59977 179 Handle(Graphic3d_AspectLine3d) Axe2Asp = new Graphic3d_AspectLine3d (acolor, atype, awidth);
180 Axe2Asp->SetType ( Aspect_TOL_DOTDASH);
181 Axe2Asp->SetWidth ( 4.);
182 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(Axe2Asp);
183
7fd59977 184 // trait d'axe: 2eme groupe
b8ddfc2f 185 aPrims = new Graphic3d_ArrayOfSegments(2);
186 aPrims->AddVertex(AttachmentPoint2);
187 aPrims->AddVertex(Proj2);
188 Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims);
7fd59977 189
190 // anneau : 3eme et 4eme groupes
a577aaab 191 Handle(Graphic3d_ArrayOfPoints) anArrayOfPoints = new Graphic3d_ArrayOfPoints (1);
192 anArrayOfPoints->AddVertex (Proj2.X(), Proj2.Y(), Proj2.Z());
7fd59977 193
194 Prs3d_Root::NewGroup(aPresentation);
195 Handle(Graphic3d_AspectMarker3d) MarkerAsp = new Graphic3d_AspectMarker3d();
196 MarkerAsp->SetType(Aspect_TOM_O);
197 MarkerAsp->SetScale(4.);
198 //MarkerAsp->SetColor(Quantity_Color(Quantity_NOC_RED));
199 MarkerAsp->SetColor(acolor);
200 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(MarkerAsp);
a577aaab 201 Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray (anArrayOfPoints);
7fd59977 202
203 Prs3d_Root::NewGroup(aPresentation);
204 Handle(Graphic3d_AspectMarker3d) Marker2Asp = new Graphic3d_AspectMarker3d();
205 Marker2Asp->SetType(Aspect_TOM_O);
206 Marker2Asp->SetScale(2.);
207 //Marker2Asp->SetColor(Quantity_Color(Quantity_NOC_GREEN));
208 Marker2Asp->SetColor(acolor);
209 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(Marker2Asp);
a577aaab 210 Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray (anArrayOfPoints);
7fd59977 211}