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