0026886: Visualization, TKV3d - eliminate global variables
[occt.git] / src / AIS / AIS_Chamf3dDimension.cxx
CommitLineData
b311480e 1// Created on: 1996-12-05
2// Created by: 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_Chamf3dDimension.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_Transformation.hxx>
7fd59977 28#include <gp_Dir.hxx>
29#include <gp_Pln.hxx>
42cf5bc1 30#include <gp_Pnt.hxx>
7fd59977 31#include <gp_Vec.hxx>
7fd59977 32#include <Precision.hxx>
7fd59977 33#include <ProjLib.hxx>
42cf5bc1 34#include <Prs3d_ArrowAspect.hxx>
35#include <Prs3d_DimensionAspect.hxx>
36#include <Prs3d_Drawer.hxx>
37#include <Prs3d_Presentation.hxx>
38#include <Prs3d_Projector.hxx>
7fd59977 39#include <Select3D_SensitiveBox.hxx>
42cf5bc1 40#include <Select3D_SensitiveSegment.hxx>
41#include <SelectMgr_EntityOwner.hxx>
42#include <SelectMgr_Selection.hxx>
43#include <Standard_NotImplemented.hxx>
44#include <Standard_Type.hxx>
45#include <TCollection_AsciiString.hxx>
46#include <TCollection_ExtendedString.hxx>
47#include <TopAbs_Orientation.hxx>
48#include <TopoDS.hxx>
49#include <TopoDS_Edge.hxx>
50#include <TopoDS_Shape.hxx>
7fd59977 51
92efcf78 52IMPLEMENT_STANDARD_RTTIEXT(AIS_Chamf3dDimension,AIS_Relation)
53
7fd59977 54//=======================================================================
55//function : Constructor
56//purpose :
57//=======================================================================
58AIS_Chamf3dDimension::AIS_Chamf3dDimension(const TopoDS_Shape& aFShape,
59 const Standard_Real aVal,
60 const TCollection_ExtendedString& aText)
61:AIS_Relation()
62{
63 myFShape = aFShape;
64 myVal = aVal;
65 myText = aText;
66 mySymbolPrs = DsgPrs_AS_LASTAR;
67 myAutomaticPosition = Standard_True;
68
69 myArrowSize = myVal / 100.;
70}
71//=======================================================================
72//function : Constructor
73//purpose :
74//=======================================================================
75AIS_Chamf3dDimension::AIS_Chamf3dDimension(const TopoDS_Shape& aFShape,
76 const Standard_Real aVal,
77 const TCollection_ExtendedString& aText,
78 const gp_Pnt& aPosition,
79 const DsgPrs_ArrowSide aSymbolPrs ,
80 const Standard_Real anArrowSize)
81:AIS_Relation()
82{
83 myFShape = aFShape;
84 myVal = aVal;
85 myText = aText;
86 myPosition = aPosition;
87 mySymbolPrs = aSymbolPrs;
7fd59977 88 SetArrowSize( anArrowSize );
7fd59977 89 myAutomaticPosition = Standard_False;
90}
91
92
93//=======================================================================
94//function : Compute
95//purpose :
96//=======================================================================
97
98void AIS_Chamf3dDimension::Compute(const Handle(PrsMgr_PresentationManager3d)& ,
99 const Handle(Prs3d_Presentation)& aPresentation,
100 const Standard_Integer)
101{
102 aPresentation->Clear();
103
104 //----------------------------
105 // Calcul du centre de la face
106 //----------------------------
107 BRepAdaptor_Surface surfAlgo (TopoDS::Face(myFShape));
108 Standard_Real uFirst, uLast, vFirst, vLast;
109 uFirst = surfAlgo.FirstUParameter();
110 uLast = surfAlgo.LastUParameter();
111 vFirst = surfAlgo.FirstVParameter();
112 vLast = surfAlgo.LastVParameter();
113 Standard_Real uMoy = (uFirst + uLast)/2;
114 Standard_Real vMoy = (vFirst + vLast)/2;
115 gp_Pnt apos ;
116 gp_Vec d1u, d1v;
117 surfAlgo.D1(uMoy, vMoy, apos, d1u, d1v);
118 myPntAttach = apos;
119
120 myDir = d1u ^ d1v;
121// myDir = surfAlgo.Plane().Axis().Direction();
122
123
124
125
126 //--------------------------------------------
127 //Calcul du point de positionnement du texte
128 //--------------------------------------------
129 gp_Pnt curpos;
130 if (myAutomaticPosition) {
131 gp_Vec transVec(myDir);
132 transVec*=myVal;
133 curpos = myPntAttach.Translated(transVec);
134
135 if (myIsSetBndBox)
136 curpos = AIS::TranslatePointToBound( curpos, myDir, myBndBox );
137
138 myPosition = curpos;
139 }
140 else {
141
142 Handle(Geom_Line) dimLin = new Geom_Line(myPntAttach, myDir);
143 Standard_Real parcurpos = ElCLib::Parameter(dimLin->Lin(),myPosition);
144 curpos = ElCLib::Value(parcurpos,dimLin->Lin());
145
146 if ( curpos.Distance(myPntAttach) < 5. ) {
147 gp_Vec transVec(myDir);
148 transVec*=5.;
149 curpos = myPntAttach.Translated(transVec);
150 }
151 myPosition = curpos;
152 }
153
a6eb515f 154 Handle(Prs3d_DimensionAspect) la = myDrawer->DimensionAspect();
155 Handle(Prs3d_ArrowAspect) arr = la->ArrowAspect();
7fd59977 156
157 //-------------------------------------------------
158 //Calcul de la boite englobante du component pour
159 //determiner la taille de la fleche
160 //-------------------------------------------------
7fd59977 161 if( !myArrowSizeIsDefined ) {
7fd59977 162 Standard_Real arrsize = myArrowSize;
163 if ( (myVal/4) < arrsize)
164 arrsize = myVal/4;
165 if (arrsize > 30.)
166 arrsize = 30.;
167 else if (arrsize < 8.)
168 arrsize = 8.;
7fd59977 169 myArrowSize = arrsize;
170 }
171 arr->SetLength(myArrowSize);
7fd59977 172
173 //Calcul de la presentation
174 DsgPrs_Chamf2dPresentation::Add(aPresentation,
175 myDrawer,
176 myPntAttach,
177 curpos,
178 myText,
179 mySymbolPrs);
180
181}
182
183//=======================================================================
184//function : Compute
185//purpose : to avoid warning
186//=======================================================================
187
188void AIS_Chamf3dDimension::Compute(const Handle(Prs3d_Projector)& aProjector,
189 const Handle(Prs3d_Presentation)& aPresentation)
190{
191// Standard_NotImplemented::Raise("AIS_Chamf3dDimension::Compute(const Handle(Prs3d_Projector)&,const Handle(Prs3d_Presentation)&)");
192 PrsMgr_PresentableObject::Compute( aProjector , aPresentation ) ;
193}
194
857ffd5e 195void AIS_Chamf3dDimension::Compute(const Handle(Prs3d_Projector)& aProjector, const Handle(Geom_Transformation)& aTransformation, const Handle(Prs3d_Presentation)& aPresentation)
7fd59977 196{
857ffd5e 197// Standard_NotImplemented::Raise("AIS_Chamf3dDimension::Compute(const Handle(Prs3d_Projector)&, const Handle(Geom_Transformation)&, const Handle(Prs3d_Presentation)&)");
7fd59977 198 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
199}
200
201//=======================================================================
202//function : ComputeSelection
203//purpose :
204//=======================================================================
205
206void AIS_Chamf3dDimension::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
207 const Standard_Integer)
208{
209 Handle(SelectMgr_EntityOwner) own = new SelectMgr_EntityOwner(this,7);
210 Handle(Select3D_SensitiveSegment) seg = new Select3D_SensitiveSegment(own,myPntAttach,myPosition);
211 aSelection->Add(seg);
212
213 // Text
214 Standard_Real size(Min(myVal/100.+1.e-6,myArrowSize+1.e-6));
215 Handle( Select3D_SensitiveBox ) box = new Select3D_SensitiveBox( own,
216 myPosition.X(),
217 myPosition.Y(),
218 myPosition.Z(),
219 myPosition.X() + size,
220 myPosition.Y() + size,
221 myPosition.Z() + size);
222 aSelection->Add(box);
223}
224