0025773: Visualization - remove AIS_Drawer class and transfer its Link() logic to...
[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#include <Standard_NotImplemented.hxx>
18
19#include <AIS_Chamf3dDimension.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_Chamf3dDimension::AIS_Chamf3dDimension(const TopoDS_Shape& aFShape,
65 const Standard_Real aVal,
66 const TCollection_ExtendedString& aText)
67:AIS_Relation()
68{
69 myFShape = aFShape;
70 myVal = aVal;
71 myText = aText;
72 mySymbolPrs = DsgPrs_AS_LASTAR;
73 myAutomaticPosition = Standard_True;
74
75 myArrowSize = myVal / 100.;
76}
77//=======================================================================
78//function : Constructor
79//purpose :
80//=======================================================================
81AIS_Chamf3dDimension::AIS_Chamf3dDimension(const TopoDS_Shape& aFShape,
82 const Standard_Real aVal,
83 const TCollection_ExtendedString& aText,
84 const gp_Pnt& aPosition,
85 const DsgPrs_ArrowSide aSymbolPrs ,
86 const Standard_Real anArrowSize)
87:AIS_Relation()
88{
89 myFShape = aFShape;
90 myVal = aVal;
91 myText = aText;
92 myPosition = aPosition;
93 mySymbolPrs = aSymbolPrs;
7fd59977 94 SetArrowSize( anArrowSize );
7fd59977 95 myAutomaticPosition = Standard_False;
96}
97
98
99//=======================================================================
100//function : Compute
101//purpose :
102//=======================================================================
103
104void AIS_Chamf3dDimension::Compute(const Handle(PrsMgr_PresentationManager3d)& ,
105 const Handle(Prs3d_Presentation)& aPresentation,
106 const Standard_Integer)
107{
108 aPresentation->Clear();
109
110 //----------------------------
111 // Calcul du centre de la face
112 //----------------------------
113 BRepAdaptor_Surface surfAlgo (TopoDS::Face(myFShape));
114 Standard_Real uFirst, uLast, vFirst, vLast;
115 uFirst = surfAlgo.FirstUParameter();
116 uLast = surfAlgo.LastUParameter();
117 vFirst = surfAlgo.FirstVParameter();
118 vLast = surfAlgo.LastVParameter();
119 Standard_Real uMoy = (uFirst + uLast)/2;
120 Standard_Real vMoy = (vFirst + vLast)/2;
121 gp_Pnt apos ;
122 gp_Vec d1u, d1v;
123 surfAlgo.D1(uMoy, vMoy, apos, d1u, d1v);
124 myPntAttach = apos;
125
126 myDir = d1u ^ d1v;
127// myDir = surfAlgo.Plane().Axis().Direction();
128
129
130
131
132 //--------------------------------------------
133 //Calcul du point de positionnement du texte
134 //--------------------------------------------
135 gp_Pnt curpos;
136 if (myAutomaticPosition) {
137 gp_Vec transVec(myDir);
138 transVec*=myVal;
139 curpos = myPntAttach.Translated(transVec);
140
141 if (myIsSetBndBox)
142 curpos = AIS::TranslatePointToBound( curpos, myDir, myBndBox );
143
144 myPosition = curpos;
145 }
146 else {
147
148 Handle(Geom_Line) dimLin = new Geom_Line(myPntAttach, myDir);
149 Standard_Real parcurpos = ElCLib::Parameter(dimLin->Lin(),myPosition);
150 curpos = ElCLib::Value(parcurpos,dimLin->Lin());
151
152 if ( curpos.Distance(myPntAttach) < 5. ) {
153 gp_Vec transVec(myDir);
154 transVec*=5.;
155 curpos = myPntAttach.Translated(transVec);
156 }
157 myPosition = curpos;
158 }
159
a6eb515f 160 Handle(Prs3d_DimensionAspect) la = myDrawer->DimensionAspect();
161 Handle(Prs3d_ArrowAspect) arr = la->ArrowAspect();
7fd59977 162
163 //-------------------------------------------------
164 //Calcul de la boite englobante du component pour
165 //determiner la taille de la fleche
166 //-------------------------------------------------
7fd59977 167 if( !myArrowSizeIsDefined ) {
7fd59977 168 Standard_Real arrsize = myArrowSize;
169 if ( (myVal/4) < arrsize)
170 arrsize = myVal/4;
171 if (arrsize > 30.)
172 arrsize = 30.;
173 else if (arrsize < 8.)
174 arrsize = 8.;
7fd59977 175 myArrowSize = arrsize;
176 }
177 arr->SetLength(myArrowSize);
7fd59977 178
179 //Calcul de la presentation
180 DsgPrs_Chamf2dPresentation::Add(aPresentation,
181 myDrawer,
182 myPntAttach,
183 curpos,
184 myText,
185 mySymbolPrs);
186
187}
188
189//=======================================================================
190//function : Compute
191//purpose : to avoid warning
192//=======================================================================
193
194void AIS_Chamf3dDimension::Compute(const Handle(Prs3d_Projector)& aProjector,
195 const Handle(Prs3d_Presentation)& aPresentation)
196{
197// Standard_NotImplemented::Raise("AIS_Chamf3dDimension::Compute(const Handle(Prs3d_Projector)&,const Handle(Prs3d_Presentation)&)");
198 PrsMgr_PresentableObject::Compute( aProjector , aPresentation ) ;
199}
200
857ffd5e 201void AIS_Chamf3dDimension::Compute(const Handle(Prs3d_Projector)& aProjector, const Handle(Geom_Transformation)& aTransformation, const Handle(Prs3d_Presentation)& aPresentation)
7fd59977 202{
857ffd5e 203// Standard_NotImplemented::Raise("AIS_Chamf3dDimension::Compute(const Handle(Prs3d_Projector)&, const Handle(Geom_Transformation)&, const Handle(Prs3d_Presentation)&)");
7fd59977 204 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
205}
206
207//=======================================================================
208//function : ComputeSelection
209//purpose :
210//=======================================================================
211
212void AIS_Chamf3dDimension::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
213 const Standard_Integer)
214{
215 Handle(SelectMgr_EntityOwner) own = new SelectMgr_EntityOwner(this,7);
216 Handle(Select3D_SensitiveSegment) seg = new Select3D_SensitiveSegment(own,myPntAttach,myPosition);
217 aSelection->Add(seg);
218
219 // Text
220 Standard_Real size(Min(myVal/100.+1.e-6,myArrowSize+1.e-6));
221 Handle( Select3D_SensitiveBox ) box = new Select3D_SensitiveBox( own,
222 myPosition.X(),
223 myPosition.Y(),
224 myPosition.Z(),
225 myPosition.X() + size,
226 myPosition.Y() + size,
227 myPosition.Z() + size);
228 aSelection->Add(box);
229}
230