| 1 | // File: AIS_Circle.cxx |
| 2 | // Created: Tue Jan 21 11:45:01 1997 |
| 3 | // Author: Prestataire Christiane ARMAND |
| 4 | // <car@chamalox.paris1.matra-dtv.fr> |
| 5 | // Copyright: Matra Datavision 1997 |
| 6 | |
| 7 | #define GER61351 //GG_171199 Enable to set an object RGB color |
| 8 | // instead a restricted object NameOfColor. |
| 9 | |
| 10 | #include <AIS_Circle.ixx> |
| 11 | #include <Aspect_TypeOfLine.hxx> |
| 12 | #include <Prs3d_Drawer.hxx> |
| 13 | #include <Prs3d_LineAspect.hxx> |
| 14 | #include <Graphic3d_ArrayOfPrimitives.hxx> |
| 15 | #include <Graphic3d_AspectLine3d.hxx> |
| 16 | #include <Graphic3d_Structure.hxx> |
| 17 | #include <TColgp_Array1OfPnt.hxx> |
| 18 | #include <SelectMgr_EntityOwner.hxx> |
| 19 | #include <Select3D_SensitiveCircle.hxx> |
| 20 | #include <StdPrs_DeflectionCurve.hxx> |
| 21 | #include <TopoDS.hxx> |
| 22 | #include <Geom_Circle.hxx> |
| 23 | #include <GeomAdaptor_Curve.hxx> |
| 24 | #include <AIS_Drawer.hxx> |
| 25 | #include <GC_MakeArcOfCircle.hxx> |
| 26 | #include <Quantity_Color.hxx> |
| 27 | #include <AIS_GraphicTool.hxx> |
| 28 | |
| 29 | //======================================================================= |
| 30 | //function : AIS_Circle |
| 31 | //purpose : |
| 32 | //======================================================================= |
| 33 | AIS_Circle::AIS_Circle(const Handle(Geom_Circle)& aComponent): |
| 34 | AIS_InteractiveObject(PrsMgr_TOP_AllView), |
| 35 | myComponent(aComponent), |
| 36 | myUStart(0.), |
| 37 | myUEnd(2*PI), |
| 38 | myCircleIsArc(Standard_False) |
| 39 | { |
| 40 | } |
| 41 | |
| 42 | //======================================================================= |
| 43 | //function : AIS_Circle |
| 44 | //purpose : |
| 45 | //======================================================================= |
| 46 | AIS_Circle::AIS_Circle(const Handle(Geom_Circle)& aComponent, |
| 47 | const Standard_Real aUStart, |
| 48 | const Standard_Real aUEnd, |
| 49 | const Standard_Boolean aSens): |
| 50 | AIS_InteractiveObject(PrsMgr_TOP_AllView) |
| 51 | { |
| 52 | myComponent = aComponent; |
| 53 | myUStart = aUStart; |
| 54 | myUEnd = aUEnd; |
| 55 | mySens = aSens; |
| 56 | myCircleIsArc = Standard_True; |
| 57 | } |
| 58 | |
| 59 | //======================================================================= |
| 60 | //function : Compute |
| 61 | //purpose : |
| 62 | //======================================================================= |
| 63 | void AIS_Circle::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/, |
| 64 | const Handle(Prs3d_Presentation)& aPresentation, |
| 65 | const Standard_Integer /*aMode*/) |
| 66 | { |
| 67 | aPresentation->Clear(); |
| 68 | |
| 69 | aPresentation->SetDisplayPriority(5); |
| 70 | |
| 71 | if (myCircleIsArc) ComputeArc(aPresentation); |
| 72 | else ComputeCircle(aPresentation); |
| 73 | |
| 74 | } |
| 75 | |
| 76 | //======================================================================= |
| 77 | //function : Compute |
| 78 | //purpose : |
| 79 | //======================================================================= |
| 80 | |
| 81 | void AIS_Circle::Compute(const Handle_Prs3d_Projector& aProjector, |
| 82 | const Handle_Geom_Transformation& aTransformation, |
| 83 | const Handle_Prs3d_Presentation& aPresentation) |
| 84 | { |
| 85 | // Standard_NotImplemented::Raise("AIS_Circle::Compute(const Handle_Prs3d_Projector&, const Handle_Geom_Transformation&, const Handle_Prs3d_Presentation&)"); |
| 86 | PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ; |
| 87 | } |
| 88 | |
| 89 | //======================================================================= |
| 90 | //function : ComputeSelection |
| 91 | //purpose : |
| 92 | //======================================================================= |
| 93 | |
| 94 | void AIS_Circle::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection, |
| 95 | const Standard_Integer /*aMode*/) |
| 96 | { |
| 97 | |
| 98 | if (myCircleIsArc) ComputeArcSelection(aSelection); |
| 99 | else ComputeCircleSelection(aSelection); |
| 100 | |
| 101 | } |
| 102 | |
| 103 | |
| 104 | //======================================================================= |
| 105 | //function : SetColor |
| 106 | //purpose : |
| 107 | //======================================================================= |
| 108 | |
| 109 | void AIS_Circle::SetColor(const Quantity_NameOfColor aCol) |
| 110 | #ifdef GER61351 |
| 111 | { |
| 112 | SetColor(Quantity_Color(aCol)); |
| 113 | } |
| 114 | |
| 115 | //======================================================================= |
| 116 | //function : SetColor |
| 117 | //purpose : |
| 118 | //======================================================================= |
| 119 | |
| 120 | void AIS_Circle::SetColor(const Quantity_Color &aCol) |
| 121 | #endif |
| 122 | { |
| 123 | hasOwnColor=Standard_True; |
| 124 | myOwnColor=aCol; |
| 125 | |
| 126 | Standard_Real WW = HasWidth()? myOwnWidth: |
| 127 | AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Line); |
| 128 | |
| 129 | if (!myDrawer->HasLineAspect ()) |
| 130 | myDrawer->SetLineAspect (new Prs3d_LineAspect(aCol,Aspect_TOL_SOLID,WW)); |
| 131 | else |
| 132 | myDrawer->LineAspect()->SetColor(aCol); |
| 133 | } |
| 134 | |
| 135 | |
| 136 | |
| 137 | //======================================================================= |
| 138 | //function : SetWidth |
| 139 | //purpose : |
| 140 | //======================================================================= |
| 141 | void AIS_Circle::SetWidth(const Standard_Real aValue) |
| 142 | { |
| 143 | myOwnWidth=aValue; |
| 144 | |
| 145 | #ifndef GER61351 |
| 146 | Quantity_NameOfColor CC = |
| 147 | HasColor() ? myOwnColor : AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line); |
| 148 | #endif |
| 149 | |
| 150 | if (!myDrawer->HasLineAspect ()) { |
| 151 | #ifdef GER61351 |
| 152 | Quantity_Color CC; |
| 153 | if( HasColor() ) CC = myOwnColor; |
| 154 | else AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line,CC); |
| 155 | #endif |
| 156 | myDrawer->SetLineAspect (new Prs3d_LineAspect(CC,Aspect_TOL_SOLID,aValue)); |
| 157 | } else |
| 158 | myDrawer->LineAspect()->SetWidth(aValue); |
| 159 | } |
| 160 | |
| 161 | |
| 162 | //======================================================================= |
| 163 | //function : UnsetColor |
| 164 | //purpose : |
| 165 | //======================================================================= |
| 166 | void AIS_Circle::UnsetColor() |
| 167 | { |
| 168 | hasOwnColor = Standard_False; |
| 169 | |
| 170 | Handle(Prs3d_LineAspect) NullAsp; |
| 171 | |
| 172 | if (!HasWidth()) myDrawer->SetLineAspect(NullAsp); |
| 173 | else{ |
| 174 | #ifdef GER61351 |
| 175 | Quantity_Color CC; |
| 176 | if( HasColor() ) CC = myOwnColor; |
| 177 | else AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line,CC); |
| 178 | #else |
| 179 | Quantity_NameOfColor CC = |
| 180 | #endif |
| 181 | AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line); |
| 182 | myDrawer->LineAspect()->SetColor(CC); |
| 183 | myOwnColor = CC; |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | //======================================================================= |
| 188 | //function : UnsetWidth |
| 189 | //purpose : |
| 190 | //======================================================================= |
| 191 | void AIS_Circle::UnsetWidth() |
| 192 | { |
| 193 | Handle(Prs3d_LineAspect) NullAsp; |
| 194 | |
| 195 | if (!HasColor()) myDrawer->SetLineAspect(NullAsp); |
| 196 | else{ |
| 197 | Standard_Real WW = AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Line); |
| 198 | myDrawer->LineAspect()->SetWidth(WW); |
| 199 | myOwnWidth = WW; |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | //======================================================================= |
| 204 | //function : ComputeCircle |
| 205 | //purpose : |
| 206 | //======================================================================= |
| 207 | void AIS_Circle::ComputeCircle( const Handle(Prs3d_Presentation)& aPresentation) |
| 208 | { |
| 209 | |
| 210 | GeomAdaptor_Curve curv(myComponent); |
| 211 | Standard_Real prevdev = myDrawer->DeviationCoefficient(); |
| 212 | myDrawer->SetDeviationCoefficient(1.e-5); |
| 213 | Standard_Boolean isPrimitiveArraysEnabled = Graphic3d_ArrayOfPrimitives::IsEnable(); |
| 214 | if(isPrimitiveArraysEnabled) Graphic3d_ArrayOfPrimitives::Disable(); |
| 215 | StdPrs_DeflectionCurve::Add(aPresentation,curv,myDrawer); |
| 216 | if(isPrimitiveArraysEnabled) Graphic3d_ArrayOfPrimitives::Enable(); |
| 217 | myDrawer->SetDeviationCoefficient(prevdev); |
| 218 | |
| 219 | } |
| 220 | |
| 221 | //======================================================================= |
| 222 | //function : ComputeArc |
| 223 | |
| 224 | //purpose : |
| 225 | //======================================================================= |
| 226 | void AIS_Circle::ComputeArc( const Handle(Prs3d_Presentation)& aPresentation) |
| 227 | { |
| 228 | |
| 229 | GeomAdaptor_Curve curv(myComponent,myUStart,myUEnd); |
| 230 | Standard_Real prevdev = myDrawer->DeviationCoefficient(); |
| 231 | myDrawer->SetDeviationCoefficient(1.e-5); |
| 232 | Standard_Boolean isPrimitiveArraysEnabled = Graphic3d_ArrayOfPrimitives::IsEnable(); |
| 233 | if(isPrimitiveArraysEnabled) Graphic3d_ArrayOfPrimitives::Disable(); |
| 234 | StdPrs_DeflectionCurve::Add(aPresentation,curv,myDrawer); |
| 235 | if(isPrimitiveArraysEnabled) Graphic3d_ArrayOfPrimitives::Enable(); |
| 236 | myDrawer->SetDeviationCoefficient(prevdev); |
| 237 | |
| 238 | } |
| 239 | |
| 240 | //======================================================================= |
| 241 | //function : ComputeCircleSelection |
| 242 | //purpose : |
| 243 | //======================================================================= |
| 244 | |
| 245 | void AIS_Circle::ComputeCircleSelection(const Handle(SelectMgr_Selection)& aSelection) |
| 246 | { |
| 247 | Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this); |
| 248 | Handle(Select3D_SensitiveCircle) seg = new Select3D_SensitiveCircle(eown, |
| 249 | myComponent); |
| 250 | aSelection->Add(seg); |
| 251 | } |
| 252 | //======================================================================= |
| 253 | //function : ComputeArcSelection |
| 254 | //purpose : |
| 255 | //======================================================================= |
| 256 | |
| 257 | void AIS_Circle::ComputeArcSelection(const Handle(SelectMgr_Selection)& aSelection) |
| 258 | { |
| 259 | |
| 260 | |
| 261 | Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this); |
| 262 | Handle(Select3D_SensitiveCircle) seg = new Select3D_SensitiveCircle(eown, |
| 263 | myComponent,myUStart,myUEnd); |
| 264 | aSelection->Add(seg); |
| 265 | } |
| 266 | //======================================================================= |
| 267 | //function : Compute |
| 268 | //purpose : to avoid warning |
| 269 | //======================================================================= |
| 270 | void AIS_Circle::Compute(const Handle(PrsMgr_PresentationManager2d)&, |
| 271 | const Handle(Graphic2d_GraphicObject)&, |
| 272 | const Standard_Integer) |
| 273 | { |
| 274 | } |
| 275 | |
| 276 | //======================================================================= |
| 277 | //function : Compute |
| 278 | //purpose : to avoid warning |
| 279 | //======================================================================= |
| 280 | void AIS_Circle::Compute(const Handle(Prs3d_Projector)&, |
| 281 | const Handle(Prs3d_Presentation)&) |
| 282 | { |
| 283 | } |