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
7 #define GER61351 //GG_171199 Enable to set an object RGB color
8 // instead a restricted object NameOfColor.
10 #include <AIS_Line.ixx>
11 #include <Aspect_TypeOfLine.hxx>
12 #include <Prs3d_Drawer.hxx>
13 #include <Precision.hxx>
14 #include <Prs3d_LineAspect.hxx>
15 #include <Graphic3d_ArrayOfPrimitives.hxx>
16 #include <Graphic3d_AspectLine3d.hxx>
17 #include <Graphic3d_Structure.hxx>
18 #include <TColgp_Array1OfPnt.hxx>
19 #include <SelectMgr_EntityOwner.hxx>
20 #include <Select3D_SensitiveSegment.hxx>
21 #include <StdPrs_Curve.hxx>
22 #include <Geom_Line.hxx>
23 #include <GeomAdaptor_Curve.hxx>
24 #include <AIS_Drawer.hxx>
25 #include <GC_MakeSegment.hxx>
26 #include <Handle_Geom_Line.hxx>
27 #include <Quantity_Color.hxx>
28 #include <AIS_GraphicTool.hxx>
29 #include <UnitsAPI.hxx>
30 //==================================================================
31 // function: FindLimits
33 //==================================================================
36 static void FindLimits(const Adaptor3d_Curve& aCurve,
37 const Standard_Real aLimit,
41 Standard_Real First = aCurve.FirstParameter();
42 Standard_Real Last = aCurve.LastParameter();
43 Standard_Boolean firstInf = Precision::IsNegativeInfinite(First);
44 Standard_Boolean lastInf = Precision::IsPositiveInfinite(Last);
47 if (firstInf || lastInf) {
48 Standard_Real delta = 1;
49 if (firstInf && lastInf) {
56 } while (P1.Distance(P2) < aLimit);
64 } while (P1.Distance(P2) < aLimit);
72 } while (P1.Distance(P2) < aLimit);
79 //=======================================================================
82 //=======================================================================
83 AIS_Line::AIS_Line(const Handle(Geom_Line)& aComponent):
84 myComponent (aComponent),
85 myLineIsSegment(Standard_False)
90 //=======================================================================
93 //=======================================================================
94 AIS_Line::AIS_Line(const Handle(Geom_Point)& aStartPoint,
95 const Handle(Geom_Point)& aEndPoint):
96 myStartPoint(aStartPoint),
97 myEndPoint(aEndPoint),
98 myLineIsSegment(Standard_True)
101 //=======================================================================
104 //=======================================================================
105 void AIS_Line::Compute(const Handle(PrsMgr_PresentationManager3d)&,
106 const Handle(Prs3d_Presentation)& aPresentation,
107 const Standard_Integer)
109 aPresentation->Clear();
111 aPresentation->SetDisplayPriority(5);
113 if (!myLineIsSegment) ComputeInfiniteLine(aPresentation);
114 else ComputeSegmentLine(aPresentation);
118 void AIS_Line::Compute(const Handle_Prs3d_Projector& aProjector, const Handle_Geom_Transformation& aTransformation, const Handle_Prs3d_Presentation& aPresentation)
120 // Standard_NotImplemented::Raise("AIS_Line::Compute(const Handle_Prs3d_Projector&, const Handle_Geom_Transformation&, const Handle_Prs3d_Presentation&)");
121 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation) ;
124 //=======================================================================
125 //function : ComputeSelection
127 //=======================================================================
129 void AIS_Line::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
130 const Standard_Integer)
133 if (!myLineIsSegment) ComputeInfiniteLineSelection(aSelection);
134 else ComputeSegmentLineSelection(aSelection);
139 //=======================================================================
140 //function : SetColor
142 //=======================================================================
144 void AIS_Line::SetColor(const Quantity_NameOfColor aCol)
147 SetColor(Quantity_Color(aCol));
150 void AIS_Line::SetColor(const Quantity_Color &aCol)
153 hasOwnColor=Standard_True;
156 Standard_Real WW = HasWidth()? myOwnWidth:
157 AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Line);
159 if (!myDrawer->HasLineAspect ())
160 myDrawer->SetLineAspect (new Prs3d_LineAspect(aCol,Aspect_TOL_SOLID,WW));
162 myDrawer->LineAspect()->SetColor(aCol);
166 //=======================================================================
167 //function : UnsetColor
169 //=======================================================================
170 void AIS_Line::UnsetColor()
172 hasOwnColor = Standard_False;
174 Handle(Prs3d_LineAspect) NullAsp;
176 if (!HasWidth()) myDrawer->SetLineAspect(NullAsp);
180 if( HasColor() ) CC = myOwnColor;
181 else AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line,CC);
183 Quantity_NameOfColor CC =
184 AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line);
187 myDrawer->LineAspect()->SetColor(CC);
192 //=======================================================================
193 //function : SetWidth
195 //=======================================================================
196 void AIS_Line::SetWidth(const Standard_Real aValue)
201 Quantity_NameOfColor CC =
202 HasColor()? myOwnColor : AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line);
205 if (!myDrawer->HasLineAspect ()) {
208 if( HasColor() ) CC = myOwnColor;
209 else AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line,CC);
211 myDrawer->SetLineAspect (new Prs3d_LineAspect(CC,Aspect_TOL_SOLID,aValue));
213 myDrawer->LineAspect()->SetWidth(aValue);
217 //=======================================================================
218 //function : UnsetWidth
220 //=======================================================================
221 void AIS_Line::UnsetWidth()
223 Handle(Prs3d_LineAspect) NullAsp;
225 if (!HasColor()) myDrawer->SetLineAspect(NullAsp);
227 Standard_Real WW = AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Line);
228 myDrawer->LineAspect()->SetWidth(WW);
233 //=======================================================================
234 //function : ComputeInfiniteLine
236 //=======================================================================
237 void AIS_Line::ComputeInfiniteLine( const Handle(Prs3d_Presentation)& aPresentation)
240 GeomAdaptor_Curve curv(myComponent);
241 Standard_Boolean isPrimitiveArraysEnabled = Graphic3d_ArrayOfPrimitives::IsEnable();
242 if(isPrimitiveArraysEnabled) Graphic3d_ArrayOfPrimitives::Disable();
243 StdPrs_Curve::Add(aPresentation,curv,myDrawer);
244 if(isPrimitiveArraysEnabled) Graphic3d_ArrayOfPrimitives::Enable();
246 //pas de prise en compte lors du FITALL
247 aPresentation->SetInfiniteState (Standard_True);
251 //=======================================================================
252 //function : ComputeSegmentLine
254 //=======================================================================
255 void AIS_Line::ComputeSegmentLine( const Handle(Prs3d_Presentation)& aPresentation)
258 gp_Pnt P1 = myStartPoint->Pnt();
259 gp_Pnt P2 = myEndPoint->Pnt();
261 myComponent = new Geom_Line(P1,gp_Dir(P2.XYZ()-P1.XYZ()));
263 Standard_Real dist = P1.Distance(P2);
264 GeomAdaptor_Curve curv(myComponent,0.,dist);
265 Standard_Boolean isPrimitiveArraysEnabled = Graphic3d_ArrayOfPrimitives::IsEnable();
266 if(isPrimitiveArraysEnabled) Graphic3d_ArrayOfPrimitives::Disable();
267 StdPrs_Curve::Add(aPresentation,curv,myDrawer);
268 if(isPrimitiveArraysEnabled) Graphic3d_ArrayOfPrimitives::Enable();
273 //=======================================================================
274 //function : ComputeInfiniteLineSelection
276 //=======================================================================
278 void AIS_Line::ComputeInfiniteLineSelection(const Handle(SelectMgr_Selection)& aSelection)
281 /* // on calcule les points min max a partir desquels on cree un segment sensible...
282 GeomAdaptor_Curve curv(myComponent);
284 FindLimits(curv,myDrawer->MaximalParameterValue(),P1,P2);
286 const gp_Dir& thedir = myComponent->Position().Direction();
287 const gp_Pnt& loc = myComponent->Position().Location();
288 const gp_XYZ& dir_xyz = thedir.XYZ();
289 const gp_XYZ& loc_xyz = loc.XYZ();
290 //POP Standard_Real aLength = UnitsAPI::CurrentToLS (250000. ,"LENGTH");
291 Standard_Real aLength = UnitsAPI::AnyToLS (250000. ,"mm");
292 gp_Pnt P1 = loc_xyz + aLength*dir_xyz;
293 gp_Pnt P2 = loc_xyz - aLength*dir_xyz;
294 Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this,5);
295 Handle(Select3D_SensitiveSegment) seg = new Select3D_SensitiveSegment(eown,P1,P2);
296 aSelection->Add(seg);
298 //=======================================================================
299 //function : ComputeSegmentLineSelection
301 //=======================================================================
303 void AIS_Line::ComputeSegmentLineSelection(const Handle(SelectMgr_Selection)& aSelection)
307 Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this,5);
308 Handle(Select3D_SensitiveSegment) seg = new Select3D_SensitiveSegment(eown,
311 aSelection->Add(seg);
313 //=======================================================================
315 //purpose : to avoid warning
316 //=======================================================================
317 void AIS_Line::Compute(const Handle(PrsMgr_PresentationManager2d)&,
318 const Handle(Graphic2d_GraphicObject)&,
319 const Standard_Integer)
323 //=======================================================================
325 //purpose : to avoid warning
326 //=======================================================================
327 void AIS_Line::Compute(const Handle(Prs3d_Projector)&,
328 const Handle(Prs3d_Presentation)&)