0031456: Visualization - move out Dimensions and Relations from package AIS to PrsDims
[occt.git] / src / PrsDim / PrsDim_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
787ff240 17#include <PrsDim_Chamf2dDimension.hxx>
7fd59977 18
787ff240 19#include <PrsDim.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>
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>
7fd59977 38#include <Select3D_SensitiveBox.hxx>
42cf5bc1 39#include <Select3D_SensitiveSegment.hxx>
40#include <SelectMgr_EntityOwner.hxx>
41#include <SelectMgr_Selection.hxx>
42#include <Standard_NotImplemented.hxx>
43#include <Standard_Type.hxx>
44#include <TCollection_AsciiString.hxx>
45#include <TCollection_ExtendedString.hxx>
46#include <TopAbs_Orientation.hxx>
47#include <TopoDS.hxx>
48#include <TopoDS_Edge.hxx>
49#include <TopoDS_Shape.hxx>
7fd59977 50
787ff240 51IMPLEMENT_STANDARD_RTTIEXT(PrsDim_Chamf2dDimension, PrsDim_Relation)
92efcf78 52
7fd59977 53//=======================================================================
54//function : Constructor
55//purpose :
56//=======================================================================
787ff240 57PrsDim_Chamf2dDimension::PrsDim_Chamf2dDimension(const TopoDS_Shape& aFShape,
7fd59977 58 const Handle(Geom_Plane)& aPlane,
59 const Standard_Real aVal,
60 const TCollection_ExtendedString& aText)
787ff240 61:PrsDim_Relation()
7fd59977 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//=======================================================================
787ff240 76PrsDim_Chamf2dDimension::PrsDim_Chamf2dDimension(const TopoDS_Shape& aFShape,
7fd59977 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)
787ff240 83:PrsDim_Relation()
7fd59977 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
787ff240 101void PrsDim_Chamf2dDimension::Compute(const Handle(PrsMgr_PresentationManager3d)& ,
7fd59977 102 const Handle(Prs3d_Presentation)& aPresentation,
103 const Standard_Integer)
104{
aa00364d 105 Handle(Geom_Curve) gcurv;
7fd59977 106 gp_Pnt pfirst,plast;
107 const TopoDS_Edge& thechamfedge = TopoDS::Edge(myFShape);
787ff240 108 if (!PrsDim::ComputeGeometry (thechamfedge, gcurv, pfirst, plast))
7fd59977 109 return;
110
aa00364d 111 Handle(Geom_Line) glin = Handle(Geom_Line)::DownCast (gcurv);
7fd59977 112 gp_Dir dir1 (glin->Position().Direction());
113 gp_Dir norm1 = myPlane->Pln().Axis().Direction();
114 myDir = norm1.Crossed(dir1);
115
116
117 //-------------------------------------------------
118 // calcul d'une direction orthogonale a l'edge du
119 // chanfrein et dirigee vers l'ext. du contour
120 //-------------------------------------------------
121
122
123 // recup. d'une edge adjacente a l'edge du chanfrein
124 /*TopoDS_Edge nextedge = TopoDS::Edge(mySShape);
125
126 gp_Pnt pfirstnext,plastnext;
127 Handle(Geom_Line) glinnext;
787ff240 128 if (!PrsDim::ComputeGeometry(nextedge,glinnext,pfirstnext,plastnext) )
7fd59977 129 return;
130
131 gp_Vec v1(pfirst,plast);
132 gp_Vec v2;
133 if (pfirst.IsEqual(plastnext, Precision::Confusion()))
134 v2.SetXYZ(pfirstnext.XYZ() - pfirst.XYZ());
135 else
136 v2.SetXYZ(plastnext.XYZ() - pfirst.XYZ());
137 gp_Vec crossvec = v1.Crossed(v2);
138
139 myDir = dimserv.GetDirection().Crossed(glin->Position().Direction());
140 if (crossvec.Dot(dimserv.GetDirection()) > 0 )
141 myDir.Reverse();*/ // myDir => donne a la creation
142
143 //--------------------------------------------
144 //Calcul du point de positionnement du texte
145 //--------------------------------------------
146 gp_Pnt curpos;
147 if (myAutomaticPosition) {
148 myPntAttach.SetXYZ((pfirst.XYZ()+plast.XYZ())/2);
149 gp_Vec transVec(myDir);
150 transVec*=myVal;
151 curpos = myPntAttach.Translated(transVec);
152
153 if (myIsSetBndBox)
787ff240 154 curpos = PrsDim::TranslatePointToBound( curpos, myDir, myBndBox );
7fd59977 155
156 myPosition = curpos;
157 }
158 else {
159
160 myPntAttach.SetXYZ((pfirst.XYZ()+plast.XYZ())/2);
161 Handle(Geom_Line) dimLin = new Geom_Line(myPntAttach, myDir);
162 Standard_Real parcurpos = ElCLib::Parameter(dimLin->Lin(),myPosition);
163 curpos = ElCLib::Value(parcurpos,dimLin->Lin());
164 //static Standard_Real minlength = 0.005;
165 //taille minimale de la dimension
166
167 if ( curpos.Distance(myPntAttach) < 5. ) {
168 gp_Vec transVec(myDir);
169 transVec*=5.;
170 curpos = myPntAttach.Translated(transVec);
171 }
172 myPosition = curpos;
173 }
174
a6eb515f 175 Handle(Prs3d_DimensionAspect) la = myDrawer->DimensionAspect();
176 Handle(Prs3d_ArrowAspect) arr = la->ArrowAspect();
7fd59977 177
178 //-------------------------------------------------
179 //Calcul de la boite englobante du component pour
180 //determiner la taille de la fleche
181 //-------------------------------------------------
182
7fd59977 183 if( !myArrowSizeIsDefined ) {
7fd59977 184 Standard_Real arrsize = myArrowSize;
185 if ( (myVal/4) < arrsize)
186 arrsize = myVal/4;
187 if (arrsize > 30.)
188 arrsize = 30.;
189 else if (arrsize < 8.)
190 arrsize = 8.;
7fd59977 191 myArrowSize = arrsize;
192 }
193 arr->SetLength(myArrowSize);
7fd59977 194
195 //Calcul de la presentation
196 DsgPrs_Chamf2dPresentation::Add(aPresentation,
197 myDrawer,
198 myPntAttach,
199 curpos,
200 myText,
201 mySymbolPrs);
202
203 }
204
205//=======================================================================
7fd59977 206//function : ComputeSelection
207//purpose :
208//=======================================================================
209
787ff240 210void PrsDim_Chamf2dDimension::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
7fd59977 211 const Standard_Integer)
212{
213 Handle(SelectMgr_EntityOwner) own = new SelectMgr_EntityOwner(this,7);
214 Handle(Select3D_SensitiveSegment) seg = new Select3D_SensitiveSegment(own,myPntAttach,myPosition);
215 aSelection->Add(seg);
216
217 // Text
218 Standard_Real size(Min(myVal/100.+1.e-6,myArrowSize+1.e-6));
219 Handle( Select3D_SensitiveBox ) box = new Select3D_SensitiveBox( own,
220 myPosition.X(),
221 myPosition.Y(),
222 myPosition.Z(),
223 myPosition.X() + size,
224 myPosition.Y() + size,
225 myPosition.Z() + size);
226 aSelection->Add(box);
227}
228