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