| 1 | // Created on: 1996-12-05 |
| 2 | // Created by: Flore Lantheaume/Odile Olivier |
| 3 | // Copyright (c) 1996-1999 Matra Datavision |
| 4 | // Copyright (c) 1999-2012 OPEN CASCADE SAS |
| 5 | // |
| 6 | // The content of this file is subject to the Open CASCADE Technology Public |
| 7 | // License Version 6.5 (the "License"). You may not use the content of this file |
| 8 | // except in compliance with the License. Please obtain a copy of the License |
| 9 | // at http://www.opencascade.org and read it completely before using this file. |
| 10 | // |
| 11 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
| 12 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
| 13 | // |
| 14 | // The Original Code and all software distributed under the License is |
| 15 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
| 16 | // Initial Developer hereby disclaims all such warranties, including without |
| 17 | // limitation, any warranties of merchantability, fitness for a particular |
| 18 | // purpose or non-infringement. Please see the License for the specific terms |
| 19 | // and conditions governing the rights and limitations under the License. |
| 20 | |
| 21 | |
| 22 | #define BUC60915 //GG 05/06/01 Enable to compute the requested arrow size |
| 23 | // if any in all dimensions. |
| 24 | |
| 25 | #include <Standard_NotImplemented.hxx> |
| 26 | |
| 27 | #include <AIS_Chamf2dDimension.ixx> |
| 28 | |
| 29 | #include <DsgPrs_Chamf2dPresentation.hxx> |
| 30 | |
| 31 | #include <Prs3d_ArrowAspect.hxx> |
| 32 | #include <Prs3d_LengthAspect.hxx> |
| 33 | #include <Prs3d_Drawer.hxx> |
| 34 | |
| 35 | #include <SelectMgr_EntityOwner.hxx> |
| 36 | #include <Select3D_SensitiveSegment.hxx> |
| 37 | |
| 38 | #include <TopoDS.hxx> |
| 39 | #include <TopoDS_Shape.hxx> |
| 40 | #include <TopoDS_Edge.hxx> |
| 41 | |
| 42 | #include <TopAbs_Orientation.hxx> |
| 43 | |
| 44 | #include <Bnd_Box.hxx> |
| 45 | #include <BRepBndLib.hxx> |
| 46 | |
| 47 | #include <gp_Dir.hxx> |
| 48 | #include <gp_Pln.hxx> |
| 49 | #include <gp_Vec.hxx> |
| 50 | |
| 51 | #include <Geom_Line.hxx> |
| 52 | |
| 53 | #include <ElCLib.hxx> |
| 54 | |
| 55 | #include <Precision.hxx> |
| 56 | |
| 57 | #include <TCollection_AsciiString.hxx> |
| 58 | #include <TCollection_ExtendedString.hxx> |
| 59 | |
| 60 | #include <BRepTools_WireExplorer.hxx> |
| 61 | |
| 62 | #include <AIS.hxx> |
| 63 | #include <AIS_Drawer.hxx> |
| 64 | |
| 65 | #include <BRepAdaptor_Surface.hxx> |
| 66 | #include <ProjLib.hxx> |
| 67 | #include <Select3D_SensitiveBox.hxx> |
| 68 | |
| 69 | //======================================================================= |
| 70 | //function : Constructor |
| 71 | //purpose : |
| 72 | //======================================================================= |
| 73 | AIS_Chamf2dDimension::AIS_Chamf2dDimension(const TopoDS_Shape& aFShape, |
| 74 | const Handle(Geom_Plane)& aPlane, |
| 75 | const Standard_Real aVal, |
| 76 | const TCollection_ExtendedString& aText) |
| 77 | :AIS_Relation() |
| 78 | { |
| 79 | myFShape = aFShape; |
| 80 | myPlane = aPlane; |
| 81 | myVal = aVal; |
| 82 | myText = aText; |
| 83 | mySymbolPrs = DsgPrs_AS_LASTAR; |
| 84 | myAutomaticPosition = Standard_True; |
| 85 | |
| 86 | myArrowSize = myVal / 100.; |
| 87 | } |
| 88 | //======================================================================= |
| 89 | //function : Constructor |
| 90 | //purpose : |
| 91 | //======================================================================= |
| 92 | AIS_Chamf2dDimension::AIS_Chamf2dDimension(const TopoDS_Shape& aFShape, |
| 93 | const Handle(Geom_Plane)& aPlane, |
| 94 | const Standard_Real aVal, |
| 95 | const TCollection_ExtendedString& aText, |
| 96 | const gp_Pnt& aPosition, |
| 97 | const DsgPrs_ArrowSide aSymbolPrs , |
| 98 | const Standard_Real anArrowSize) |
| 99 | :AIS_Relation() |
| 100 | { |
| 101 | myFShape = aFShape; |
| 102 | myPlane = aPlane; |
| 103 | myVal = aVal; |
| 104 | myText = aText; |
| 105 | myPosition = aPosition; |
| 106 | mySymbolPrs = aSymbolPrs; |
| 107 | #ifdef BUC60915 |
| 108 | SetArrowSize( anArrowSize ); |
| 109 | #else |
| 110 | myArrowSize = anArrowSize; |
| 111 | #endif |
| 112 | myAutomaticPosition = Standard_False; |
| 113 | } |
| 114 | |
| 115 | |
| 116 | //======================================================================= |
| 117 | //function : Compute |
| 118 | //purpose : |
| 119 | //======================================================================= |
| 120 | |
| 121 | void AIS_Chamf2dDimension::Compute(const Handle(PrsMgr_PresentationManager3d)& , |
| 122 | const Handle(Prs3d_Presentation)& aPresentation, |
| 123 | const Standard_Integer) |
| 124 | { |
| 125 | aPresentation->Clear(); |
| 126 | |
| 127 | Handle(Geom_Line) glin; |
| 128 | gp_Pnt pfirst,plast; |
| 129 | const TopoDS_Edge& thechamfedge = TopoDS::Edge(myFShape); |
| 130 | if (!AIS::ComputeGeometry(thechamfedge, glin,pfirst,plast) ) |
| 131 | return; |
| 132 | |
| 133 | |
| 134 | gp_Dir dir1 (glin->Position().Direction()); |
| 135 | gp_Dir norm1 = myPlane->Pln().Axis().Direction(); |
| 136 | myDir = norm1.Crossed(dir1); |
| 137 | |
| 138 | |
| 139 | //------------------------------------------------- |
| 140 | // calcul d'une direction orthogonale a l'edge du |
| 141 | // chanfrein et dirigee vers l'ext. du contour |
| 142 | //------------------------------------------------- |
| 143 | |
| 144 | |
| 145 | // recup. d'une edge adjacente a l'edge du chanfrein |
| 146 | /*TopoDS_Edge nextedge = TopoDS::Edge(mySShape); |
| 147 | |
| 148 | gp_Pnt pfirstnext,plastnext; |
| 149 | Handle(Geom_Line) glinnext; |
| 150 | if (!AIS::ComputeGeometry(nextedge,glinnext,pfirstnext,plastnext) ) |
| 151 | return; |
| 152 | |
| 153 | gp_Vec v1(pfirst,plast); |
| 154 | gp_Vec v2; |
| 155 | if (pfirst.IsEqual(plastnext, Precision::Confusion())) |
| 156 | v2.SetXYZ(pfirstnext.XYZ() - pfirst.XYZ()); |
| 157 | else |
| 158 | v2.SetXYZ(plastnext.XYZ() - pfirst.XYZ()); |
| 159 | gp_Vec crossvec = v1.Crossed(v2); |
| 160 | |
| 161 | myDir = dimserv.GetDirection().Crossed(glin->Position().Direction()); |
| 162 | if (crossvec.Dot(dimserv.GetDirection()) > 0 ) |
| 163 | myDir.Reverse();*/ // myDir => donne a la creation |
| 164 | |
| 165 | //-------------------------------------------- |
| 166 | //Calcul du point de positionnement du texte |
| 167 | //-------------------------------------------- |
| 168 | gp_Pnt curpos; |
| 169 | if (myAutomaticPosition) { |
| 170 | myPntAttach.SetXYZ((pfirst.XYZ()+plast.XYZ())/2); |
| 171 | gp_Vec transVec(myDir); |
| 172 | transVec*=myVal; |
| 173 | curpos = myPntAttach.Translated(transVec); |
| 174 | |
| 175 | if (myIsSetBndBox) |
| 176 | curpos = AIS::TranslatePointToBound( curpos, myDir, myBndBox ); |
| 177 | |
| 178 | myPosition = curpos; |
| 179 | } |
| 180 | else { |
| 181 | |
| 182 | myPntAttach.SetXYZ((pfirst.XYZ()+plast.XYZ())/2); |
| 183 | Handle(Geom_Line) dimLin = new Geom_Line(myPntAttach, myDir); |
| 184 | Standard_Real parcurpos = ElCLib::Parameter(dimLin->Lin(),myPosition); |
| 185 | curpos = ElCLib::Value(parcurpos,dimLin->Lin()); |
| 186 | //static Standard_Real minlength = 0.005; |
| 187 | //taille minimale de la dimension |
| 188 | |
| 189 | if ( curpos.Distance(myPntAttach) < 5. ) { |
| 190 | gp_Vec transVec(myDir); |
| 191 | transVec*=5.; |
| 192 | curpos = myPntAttach.Translated(transVec); |
| 193 | } |
| 194 | myPosition = curpos; |
| 195 | } |
| 196 | |
| 197 | Handle(Prs3d_LengthAspect) la = myDrawer->LengthAspect(); |
| 198 | Handle(Prs3d_ArrowAspect) arr = la->Arrow1Aspect(); |
| 199 | |
| 200 | //------------------------------------------------- |
| 201 | //Calcul de la boite englobante du component pour |
| 202 | //determiner la taille de la fleche |
| 203 | //------------------------------------------------- |
| 204 | |
| 205 | #ifdef BUC60915 |
| 206 | if( !myArrowSizeIsDefined ) { |
| 207 | #endif |
| 208 | Standard_Real arrsize = myArrowSize; |
| 209 | if ( (myVal/4) < arrsize) |
| 210 | arrsize = myVal/4; |
| 211 | if (arrsize > 30.) |
| 212 | arrsize = 30.; |
| 213 | else if (arrsize < 8.) |
| 214 | arrsize = 8.; |
| 215 | #ifdef BUC60915 |
| 216 | myArrowSize = arrsize; |
| 217 | } |
| 218 | arr->SetLength(myArrowSize); |
| 219 | #else |
| 220 | arr->SetLength(arrsize); |
| 221 | #endif |
| 222 | |
| 223 | //Calcul de la presentation |
| 224 | DsgPrs_Chamf2dPresentation::Add(aPresentation, |
| 225 | myDrawer, |
| 226 | myPntAttach, |
| 227 | curpos, |
| 228 | myText, |
| 229 | mySymbolPrs); |
| 230 | |
| 231 | } |
| 232 | |
| 233 | //======================================================================= |
| 234 | //function : Compute |
| 235 | //purpose : to avoid warning |
| 236 | //======================================================================= |
| 237 | |
| 238 | void AIS_Chamf2dDimension::Compute(const Handle(Prs3d_Projector)& aProjector, |
| 239 | const Handle(Prs3d_Presentation)& aPresentation) |
| 240 | { |
| 241 | // Standard_NotImplemented::Raise("AIS_Chamf2dDimension::Compute(const Handle(Prs3d_Projector)&,const Handle(Prs3d_Presentation)&)"); |
| 242 | PrsMgr_PresentableObject::Compute( aProjector , aPresentation ) ; |
| 243 | } |
| 244 | |
| 245 | //======================================================================= |
| 246 | //function : Compute |
| 247 | //purpose : to avoid warning |
| 248 | //======================================================================= |
| 249 | |
| 250 | void AIS_Chamf2dDimension::Compute(const Handle(PrsMgr_PresentationManager2d)& aPresentationManager2d, |
| 251 | const Handle(Graphic2d_GraphicObject)& aGraphicObject, |
| 252 | const Standard_Integer anInteger) |
| 253 | { |
| 254 | // Standard_NotImplemented::Raise("AIS_Chamf2dDimension::Compute(const Handle(PrsMgr_PresentationManager2d)&,const Handle(Graphic2d_GraphicObject)&,const Standard_Integer)"); |
| 255 | PrsMgr_PresentableObject::Compute( aPresentationManager2d ,aGraphicObject,anInteger) ; |
| 256 | } |
| 257 | |
| 258 | void AIS_Chamf2dDimension::Compute(const Handle_Prs3d_Projector& aProjector, const Handle_Geom_Transformation& aTransformation, const Handle_Prs3d_Presentation& aPresentation) |
| 259 | { |
| 260 | // Standard_NotImplemented::Raise("AIS_Chamf2dDimension::Compute(const Handle_Prs3d_Projector&, const Handle_Geom_Transformation&, const Handle_Prs3d_Presentation&)"); |
| 261 | PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ; |
| 262 | } |
| 263 | |
| 264 | //======================================================================= |
| 265 | //function : ComputeSelection |
| 266 | //purpose : |
| 267 | //======================================================================= |
| 268 | |
| 269 | void AIS_Chamf2dDimension::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection, |
| 270 | const Standard_Integer) |
| 271 | { |
| 272 | Handle(SelectMgr_EntityOwner) own = new SelectMgr_EntityOwner(this,7); |
| 273 | Handle(Select3D_SensitiveSegment) seg = new Select3D_SensitiveSegment(own,myPntAttach,myPosition); |
| 274 | aSelection->Add(seg); |
| 275 | |
| 276 | // Text |
| 277 | Standard_Real size(Min(myVal/100.+1.e-6,myArrowSize+1.e-6)); |
| 278 | Handle( Select3D_SensitiveBox ) box = new Select3D_SensitiveBox( own, |
| 279 | myPosition.X(), |
| 280 | myPosition.Y(), |
| 281 | myPosition.Z(), |
| 282 | myPosition.X() + size, |
| 283 | myPosition.Y() + size, |
| 284 | myPosition.Z() + size); |
| 285 | aSelection->Add(box); |
| 286 | } |
| 287 | |