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