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