0025773: Visualization - remove AIS_Drawer class and transfer its Link() logic to...
[occt.git] / src / AIS / AIS_Chamf2dDimension.cxx
CommitLineData
b311480e 1// Created on: 1996-12-05
2// Created by: Flore Lantheaume/Odile Olivier
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.
7fd59977 16
7fd59977 17#include <Standard_NotImplemented.hxx>
18
19#include <AIS_Chamf2dDimension.ixx>
20
21#include <DsgPrs_Chamf2dPresentation.hxx>
22
23#include <Prs3d_ArrowAspect.hxx>
a6eb515f 24#include <Prs3d_DimensionAspect.hxx>
7fd59977 25#include <Prs3d_Drawer.hxx>
26
27#include <SelectMgr_EntityOwner.hxx>
28#include <Select3D_SensitiveSegment.hxx>
29
30#include <TopoDS.hxx>
31#include <TopoDS_Shape.hxx>
32#include <TopoDS_Edge.hxx>
33
34#include <TopAbs_Orientation.hxx>
35
36#include <Bnd_Box.hxx>
37#include <BRepBndLib.hxx>
38
39#include <gp_Dir.hxx>
40#include <gp_Pln.hxx>
41#include <gp_Vec.hxx>
42
43#include <Geom_Line.hxx>
44
45#include <ElCLib.hxx>
46
47#include <Precision.hxx>
48
49#include <TCollection_AsciiString.hxx>
50#include <TCollection_ExtendedString.hxx>
51
52#include <BRepTools_WireExplorer.hxx>
53
54#include <AIS.hxx>
7fd59977 55
56#include <BRepAdaptor_Surface.hxx>
57#include <ProjLib.hxx>
58#include <Select3D_SensitiveBox.hxx>
59
60//=======================================================================
61//function : Constructor
62//purpose :
63//=======================================================================
64AIS_Chamf2dDimension::AIS_Chamf2dDimension(const TopoDS_Shape& aFShape,
65 const Handle(Geom_Plane)& aPlane,
66 const Standard_Real aVal,
67 const TCollection_ExtendedString& aText)
68:AIS_Relation()
69{
70 myFShape = aFShape;
71 myPlane = aPlane;
72 myVal = aVal;
73 myText = aText;
74 mySymbolPrs = DsgPrs_AS_LASTAR;
75 myAutomaticPosition = Standard_True;
76
77 myArrowSize = myVal / 100.;
78}
79//=======================================================================
80//function : Constructor
81//purpose :
82//=======================================================================
83AIS_Chamf2dDimension::AIS_Chamf2dDimension(const TopoDS_Shape& aFShape,
84 const Handle(Geom_Plane)& aPlane,
85 const Standard_Real aVal,
86 const TCollection_ExtendedString& aText,
87 const gp_Pnt& aPosition,
88 const DsgPrs_ArrowSide aSymbolPrs ,
89 const Standard_Real anArrowSize)
90:AIS_Relation()
91{
92 myFShape = aFShape;
93 myPlane = aPlane;
94 myVal = aVal;
95 myText = aText;
96 myPosition = aPosition;
97 mySymbolPrs = aSymbolPrs;
7fd59977 98 SetArrowSize( anArrowSize );
7fd59977 99 myAutomaticPosition = Standard_False;
100}
101
102
103//=======================================================================
104//function : Compute
105//purpose :
106//=======================================================================
107
108void AIS_Chamf2dDimension::Compute(const Handle(PrsMgr_PresentationManager3d)& ,
109 const Handle(Prs3d_Presentation)& aPresentation,
110 const Standard_Integer)
111{
112 aPresentation->Clear();
113
114 Handle(Geom_Line) glin;
115 gp_Pnt pfirst,plast;
116 const TopoDS_Edge& thechamfedge = TopoDS::Edge(myFShape);
117 if (!AIS::ComputeGeometry(thechamfedge, glin,pfirst,plast) )
118 return;
119
120
121 gp_Dir dir1 (glin->Position().Direction());
122 gp_Dir norm1 = myPlane->Pln().Axis().Direction();
123 myDir = norm1.Crossed(dir1);
124
125
126 //-------------------------------------------------
127 // calcul d'une direction orthogonale a l'edge du
128 // chanfrein et dirigee vers l'ext. du contour
129 //-------------------------------------------------
130
131
132 // recup. d'une edge adjacente a l'edge du chanfrein
133 /*TopoDS_Edge nextedge = TopoDS::Edge(mySShape);
134
135 gp_Pnt pfirstnext,plastnext;
136 Handle(Geom_Line) glinnext;
137 if (!AIS::ComputeGeometry(nextedge,glinnext,pfirstnext,plastnext) )
138 return;
139
140 gp_Vec v1(pfirst,plast);
141 gp_Vec v2;
142 if (pfirst.IsEqual(plastnext, Precision::Confusion()))
143 v2.SetXYZ(pfirstnext.XYZ() - pfirst.XYZ());
144 else
145 v2.SetXYZ(plastnext.XYZ() - pfirst.XYZ());
146 gp_Vec crossvec = v1.Crossed(v2);
147
148 myDir = dimserv.GetDirection().Crossed(glin->Position().Direction());
149 if (crossvec.Dot(dimserv.GetDirection()) > 0 )
150 myDir.Reverse();*/ // myDir => donne a la creation
151
152 //--------------------------------------------
153 //Calcul du point de positionnement du texte
154 //--------------------------------------------
155 gp_Pnt curpos;
156 if (myAutomaticPosition) {
157 myPntAttach.SetXYZ((pfirst.XYZ()+plast.XYZ())/2);
158 gp_Vec transVec(myDir);
159 transVec*=myVal;
160 curpos = myPntAttach.Translated(transVec);
161
162 if (myIsSetBndBox)
163 curpos = AIS::TranslatePointToBound( curpos, myDir, myBndBox );
164
165 myPosition = curpos;
166 }
167 else {
168
169 myPntAttach.SetXYZ((pfirst.XYZ()+plast.XYZ())/2);
170 Handle(Geom_Line) dimLin = new Geom_Line(myPntAttach, myDir);
171 Standard_Real parcurpos = ElCLib::Parameter(dimLin->Lin(),myPosition);
172 curpos = ElCLib::Value(parcurpos,dimLin->Lin());
173 //static Standard_Real minlength = 0.005;
174 //taille minimale de la dimension
175
176 if ( curpos.Distance(myPntAttach) < 5. ) {
177 gp_Vec transVec(myDir);
178 transVec*=5.;
179 curpos = myPntAttach.Translated(transVec);
180 }
181 myPosition = curpos;
182 }
183
a6eb515f 184 Handle(Prs3d_DimensionAspect) la = myDrawer->DimensionAspect();
185 Handle(Prs3d_ArrowAspect) arr = la->ArrowAspect();
7fd59977 186
187 //-------------------------------------------------
188 //Calcul de la boite englobante du component pour
189 //determiner la taille de la fleche
190 //-------------------------------------------------
191
7fd59977 192 if( !myArrowSizeIsDefined ) {
7fd59977 193 Standard_Real arrsize = myArrowSize;
194 if ( (myVal/4) < arrsize)
195 arrsize = myVal/4;
196 if (arrsize > 30.)
197 arrsize = 30.;
198 else if (arrsize < 8.)
199 arrsize = 8.;
7fd59977 200 myArrowSize = arrsize;
201 }
202 arr->SetLength(myArrowSize);
7fd59977 203
204 //Calcul de la presentation
205 DsgPrs_Chamf2dPresentation::Add(aPresentation,
206 myDrawer,
207 myPntAttach,
208 curpos,
209 myText,
210 mySymbolPrs);
211
212 }
213
214//=======================================================================
215//function : Compute
216//purpose : to avoid warning
217//=======================================================================
218
219void AIS_Chamf2dDimension::Compute(const Handle(Prs3d_Projector)& aProjector,
220 const Handle(Prs3d_Presentation)& aPresentation)
221{
222// Standard_NotImplemented::Raise("AIS_Chamf2dDimension::Compute(const Handle(Prs3d_Projector)&,const Handle(Prs3d_Presentation)&)");
223 PrsMgr_PresentableObject::Compute( aProjector , aPresentation ) ;
224}
225
857ffd5e 226void AIS_Chamf2dDimension::Compute(const Handle(Prs3d_Projector)& aProjector, const Handle(Geom_Transformation)& aTransformation, const Handle(Prs3d_Presentation)& aPresentation)
7fd59977 227{
857ffd5e 228// Standard_NotImplemented::Raise("AIS_Chamf2dDimension::Compute(const Handle(Prs3d_Projector)&, const Handle(Geom_Transformation)&, const Handle(Prs3d_Presentation)&)");
7fd59977 229 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
230}
231
232//=======================================================================
233//function : ComputeSelection
234//purpose :
235//=======================================================================
236
237void AIS_Chamf2dDimension::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
238 const Standard_Integer)
239{
240 Handle(SelectMgr_EntityOwner) own = new SelectMgr_EntityOwner(this,7);
241 Handle(Select3D_SensitiveSegment) seg = new Select3D_SensitiveSegment(own,myPntAttach,myPosition);
242 aSelection->Add(seg);
243
244 // Text
245 Standard_Real size(Min(myVal/100.+1.e-6,myArrowSize+1.e-6));
246 Handle( Select3D_SensitiveBox ) box = new Select3D_SensitiveBox( own,
247 myPosition.X(),
248 myPosition.Y(),
249 myPosition.Z(),
250 myPosition.X() + size,
251 myPosition.Y() + size,
252 myPosition.Z() + size);
253 aSelection->Add(box);
254}
255