| 1 | // Created on: 1997-01-21 |
| 2 | // Created by: Prestataire Christiane ARMAND |
| 3 | // Copyright (c) 1997-1999 Matra Datavision |
| 4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
| 5 | // |
| 6 | // This file is part of Open CASCADE Technology software library. |
| 7 | // |
| 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 |
| 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. |
| 13 | // |
| 14 | // Alternatively, this file may be used under the terms of Open CASCADE |
| 15 | // commercial license or contractual agreement. |
| 16 | |
| 17 | #include <AIS_Line.ixx> |
| 18 | #include <Aspect_TypeOfLine.hxx> |
| 19 | #include <Prs3d_Drawer.hxx> |
| 20 | #include <Precision.hxx> |
| 21 | #include <Prs3d_LineAspect.hxx> |
| 22 | #include <Graphic3d_AspectLine3d.hxx> |
| 23 | #include <Graphic3d_Structure.hxx> |
| 24 | #include <TColgp_Array1OfPnt.hxx> |
| 25 | #include <SelectMgr_EntityOwner.hxx> |
| 26 | #include <Select3D_SensitiveSegment.hxx> |
| 27 | #include <StdPrs_Curve.hxx> |
| 28 | #include <Geom_Line.hxx> |
| 29 | #include <GeomAdaptor_Curve.hxx> |
| 30 | #include <GC_MakeSegment.hxx> |
| 31 | #include <Geom_Line.hxx> |
| 32 | #include <Quantity_Color.hxx> |
| 33 | #include <AIS_GraphicTool.hxx> |
| 34 | #include <UnitsAPI.hxx> |
| 35 | |
| 36 | //================================================================== |
| 37 | // function: FindLimits |
| 38 | // purpose: |
| 39 | //================================================================== |
| 40 | //unused |
| 41 | /*#ifdef OCCT_DEBUG |
| 42 | static void FindLimits(const Adaptor3d_Curve& aCurve, |
| 43 | const Standard_Real aLimit, |
| 44 | gp_Pnt& P1, |
| 45 | gp_Pnt& P2) |
| 46 | { |
| 47 | Standard_Real First = aCurve.FirstParameter(); |
| 48 | Standard_Real Last = aCurve.LastParameter(); |
| 49 | Standard_Boolean firstInf = Precision::IsNegativeInfinite(First); |
| 50 | Standard_Boolean lastInf = Precision::IsPositiveInfinite(Last); |
| 51 | |
| 52 | |
| 53 | if (firstInf || lastInf) { |
| 54 | Standard_Real delta = 1; |
| 55 | if (firstInf && lastInf) { |
| 56 | do { |
| 57 | delta *= 2; |
| 58 | First = - delta; |
| 59 | Last = delta; |
| 60 | aCurve.D0(First,P1); |
| 61 | aCurve.D0(Last,P2); |
| 62 | } while (P1.Distance(P2) < aLimit); |
| 63 | } |
| 64 | else if (firstInf) { |
| 65 | aCurve.D0(Last,P2); |
| 66 | do { |
| 67 | delta *= 2; |
| 68 | First = Last - delta; |
| 69 | aCurve.D0(First,P1); |
| 70 | } while (P1.Distance(P2) < aLimit); |
| 71 | } |
| 72 | else if (lastInf) { |
| 73 | aCurve.D0(First,P1); |
| 74 | do { |
| 75 | delta *= 2; |
| 76 | Last = First + delta; |
| 77 | aCurve.D0(Last,P2); |
| 78 | } while (P1.Distance(P2) < aLimit); |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | #endif |
| 83 | */ |
| 84 | |
| 85 | //======================================================================= |
| 86 | //function : AIS_Line |
| 87 | //purpose : |
| 88 | //======================================================================= |
| 89 | AIS_Line::AIS_Line(const Handle(Geom_Line)& aComponent): |
| 90 | myComponent (aComponent), |
| 91 | myLineIsSegment(Standard_False) |
| 92 | { |
| 93 | SetInfiniteState(); |
| 94 | } |
| 95 | |
| 96 | //======================================================================= |
| 97 | //function : AIS_Line |
| 98 | //purpose : |
| 99 | //======================================================================= |
| 100 | AIS_Line::AIS_Line(const Handle(Geom_Point)& aStartPoint, |
| 101 | const Handle(Geom_Point)& aEndPoint): |
| 102 | myStartPoint(aStartPoint), |
| 103 | myEndPoint(aEndPoint), |
| 104 | myLineIsSegment(Standard_True) |
| 105 | {} |
| 106 | |
| 107 | //======================================================================= |
| 108 | //function : Compute |
| 109 | //purpose : |
| 110 | //======================================================================= |
| 111 | void AIS_Line::Compute(const Handle(PrsMgr_PresentationManager3d)&, |
| 112 | const Handle(Prs3d_Presentation)& aPresentation, |
| 113 | const Standard_Integer) |
| 114 | { |
| 115 | aPresentation->Clear(); |
| 116 | |
| 117 | aPresentation->SetDisplayPriority(5); |
| 118 | |
| 119 | if (!myLineIsSegment) ComputeInfiniteLine(aPresentation); |
| 120 | else ComputeSegmentLine(aPresentation); |
| 121 | |
| 122 | } |
| 123 | |
| 124 | void AIS_Line::Compute(const Handle(Prs3d_Projector)& aProjector, const Handle(Geom_Transformation)& aTransformation, const Handle(Prs3d_Presentation)& aPresentation) |
| 125 | { |
| 126 | // Standard_NotImplemented::Raise("AIS_Line::Compute(const Handle(Prs3d_Projector)&, const Handle(Geom_Transformation)&, const Handle(Prs3d_Presentation)&)"); |
| 127 | PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation) ; |
| 128 | } |
| 129 | |
| 130 | //======================================================================= |
| 131 | //function : ComputeSelection |
| 132 | //purpose : |
| 133 | //======================================================================= |
| 134 | |
| 135 | void AIS_Line::ComputeSelection(const Handle(SelectMgr_Selection)& theSelection, |
| 136 | const Standard_Integer theMode) |
| 137 | { |
| 138 | // Do not support selection modes different from 0 currently |
| 139 | if (theMode) |
| 140 | return; |
| 141 | |
| 142 | if (!myLineIsSegment) |
| 143 | { |
| 144 | ComputeInfiniteLineSelection(theSelection); |
| 145 | } |
| 146 | else |
| 147 | { |
| 148 | ComputeSegmentLineSelection(theSelection); |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | |
| 153 | //======================================================================= |
| 154 | //function : SetColor |
| 155 | //purpose : |
| 156 | //======================================================================= |
| 157 | |
| 158 | void AIS_Line::SetColor(const Quantity_NameOfColor aCol) |
| 159 | { |
| 160 | SetColor(Quantity_Color(aCol)); |
| 161 | } |
| 162 | |
| 163 | void AIS_Line::SetColor(const Quantity_Color &aCol) |
| 164 | { |
| 165 | hasOwnColor=Standard_True; |
| 166 | myOwnColor=aCol; |
| 167 | |
| 168 | Standard_Real WW = HasWidth()? myOwnWidth: |
| 169 | myDrawer->HasLink() ? |
| 170 | AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Line) : 1.; |
| 171 | |
| 172 | if (!myDrawer->HasOwnLineAspect ()) |
| 173 | myDrawer->SetLineAspect (new Prs3d_LineAspect(aCol,Aspect_TOL_SOLID,WW)); |
| 174 | else |
| 175 | myDrawer->LineAspect()->SetColor(aCol); |
| 176 | } |
| 177 | |
| 178 | |
| 179 | //======================================================================= |
| 180 | //function : UnsetColor |
| 181 | //purpose : |
| 182 | //======================================================================= |
| 183 | void AIS_Line::UnsetColor() |
| 184 | { |
| 185 | hasOwnColor = Standard_False; |
| 186 | |
| 187 | Handle(Prs3d_LineAspect) NullAsp; |
| 188 | |
| 189 | if (!HasWidth()) myDrawer->SetLineAspect(NullAsp); |
| 190 | else{ |
| 191 | Quantity_Color CC = Quantity_NOC_YELLOW; |
| 192 | if( HasColor() ) CC = myOwnColor; |
| 193 | else if (myDrawer->HasLink()) AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Line, CC); |
| 194 | myDrawer->LineAspect()->SetColor(CC); |
| 195 | myOwnColor = CC; |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | //======================================================================= |
| 200 | //function : SetWidth |
| 201 | //purpose : |
| 202 | //======================================================================= |
| 203 | void AIS_Line::SetWidth(const Standard_Real aValue) |
| 204 | { |
| 205 | myOwnWidth=aValue; |
| 206 | |
| 207 | if (!myDrawer->HasOwnLineAspect ()) { |
| 208 | Quantity_Color CC = Quantity_NOC_YELLOW; |
| 209 | if( HasColor() ) CC = myOwnColor; |
| 210 | else if(myDrawer->HasLink()) AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Line, CC); |
| 211 | myDrawer->SetLineAspect (new Prs3d_LineAspect (CC, Aspect_TOL_SOLID, aValue)); |
| 212 | } else |
| 213 | myDrawer->LineAspect()->SetWidth(aValue); |
| 214 | } |
| 215 | |
| 216 | |
| 217 | //======================================================================= |
| 218 | //function : UnsetWidth |
| 219 | //purpose : |
| 220 | //======================================================================= |
| 221 | void AIS_Line::UnsetWidth() |
| 222 | { |
| 223 | Handle(Prs3d_LineAspect) NullAsp; |
| 224 | |
| 225 | if (!HasColor()) myDrawer->SetLineAspect(NullAsp); |
| 226 | else{ |
| 227 | Standard_Real WW = myDrawer->HasLink() ? |
| 228 | AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Line) : 1.; |
| 229 | myDrawer->LineAspect()->SetWidth(WW); |
| 230 | myOwnWidth = WW; |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | //======================================================================= |
| 235 | //function : ComputeInfiniteLine |
| 236 | //purpose : |
| 237 | //======================================================================= |
| 238 | void AIS_Line::ComputeInfiniteLine( const Handle(Prs3d_Presentation)& aPresentation) |
| 239 | { |
| 240 | GeomAdaptor_Curve curv(myComponent); |
| 241 | StdPrs_Curve::Add(aPresentation,curv,myDrawer); |
| 242 | |
| 243 | //pas de prise en compte lors du FITALL |
| 244 | aPresentation->SetInfiniteState (Standard_True); |
| 245 | } |
| 246 | |
| 247 | //======================================================================= |
| 248 | //function : ComputeSegmentLine |
| 249 | //purpose : |
| 250 | //======================================================================= |
| 251 | void AIS_Line::ComputeSegmentLine( const Handle(Prs3d_Presentation)& aPresentation) |
| 252 | { |
| 253 | gp_Pnt P1 = myStartPoint->Pnt(); |
| 254 | gp_Pnt P2 = myEndPoint->Pnt(); |
| 255 | |
| 256 | myComponent = new Geom_Line(P1,gp_Dir(P2.XYZ()-P1.XYZ())); |
| 257 | |
| 258 | Standard_Real dist = P1.Distance(P2); |
| 259 | GeomAdaptor_Curve curv(myComponent,0.,dist); |
| 260 | StdPrs_Curve::Add(aPresentation,curv,myDrawer); |
| 261 | } |
| 262 | |
| 263 | |
| 264 | //======================================================================= |
| 265 | //function : ComputeInfiniteLineSelection |
| 266 | //purpose : |
| 267 | //======================================================================= |
| 268 | |
| 269 | void AIS_Line::ComputeInfiniteLineSelection(const Handle(SelectMgr_Selection)& aSelection) |
| 270 | { |
| 271 | |
| 272 | /* // on calcule les points min max a partir desquels on cree un segment sensible... |
| 273 | GeomAdaptor_Curve curv(myComponent); |
| 274 | gp_Pnt P1,P2; |
| 275 | FindLimits(curv,myDrawer->MaximalParameterValue(),P1,P2); |
| 276 | */ |
| 277 | const gp_Dir& thedir = myComponent->Position().Direction(); |
| 278 | const gp_Pnt& loc = myComponent->Position().Location(); |
| 279 | const gp_XYZ& dir_xyz = thedir.XYZ(); |
| 280 | const gp_XYZ& loc_xyz = loc.XYZ(); |
| 281 | //POP Standard_Real aLength = UnitsAPI::CurrentToLS (250000. ,"LENGTH"); |
| 282 | Standard_Real aLength = UnitsAPI::AnyToLS (250000. ,"mm"); |
| 283 | gp_Pnt P1 = loc_xyz + aLength*dir_xyz; |
| 284 | gp_Pnt P2 = loc_xyz - aLength*dir_xyz; |
| 285 | Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this,5); |
| 286 | Handle(Select3D_SensitiveSegment) seg = new Select3D_SensitiveSegment(eown,P1,P2); |
| 287 | aSelection->Add(seg); |
| 288 | } |
| 289 | //======================================================================= |
| 290 | //function : ComputeSegmentLineSelection |
| 291 | //purpose : |
| 292 | //======================================================================= |
| 293 | |
| 294 | void AIS_Line::ComputeSegmentLineSelection(const Handle(SelectMgr_Selection)& aSelection) |
| 295 | { |
| 296 | |
| 297 | |
| 298 | Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this,5); |
| 299 | Handle(Select3D_SensitiveSegment) seg = new Select3D_SensitiveSegment(eown, |
| 300 | myStartPoint->Pnt(), |
| 301 | myEndPoint->Pnt()); |
| 302 | aSelection->Add(seg); |
| 303 | } |
| 304 | |
| 305 | //======================================================================= |
| 306 | //function : Compute |
| 307 | //purpose : to avoid warning |
| 308 | //======================================================================= |
| 309 | void AIS_Line::Compute(const Handle(Prs3d_Projector)&, |
| 310 | const Handle(Prs3d_Presentation)&) |
| 311 | { |
| 312 | } |
| 313 | |
| 314 | |
| 315 | |
| 316 | |