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
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <AIS_GraphicTool.hxx>
19 #include <AIS_Line.hxx>
20 #include <Aspect_TypeOfLine.hxx>
21 #include <GC_MakeSegment.hxx>
22 #include <Geom_Line.hxx>
23 #include <Geom_Point.hxx>
24 #include <Geom_Transformation.hxx>
25 #include <GeomAdaptor_Curve.hxx>
26 #include <Graphic3d_AspectLine3d.hxx>
27 #include <Graphic3d_Structure.hxx>
28 #include <Precision.hxx>
29 #include <Prs3d_Drawer.hxx>
30 #include <Prs3d_LineAspect.hxx>
31 #include <Prs3d_Presentation.hxx>
32 #include <Prs3d_Projector.hxx>
33 #include <Quantity_Color.hxx>
34 #include <Select3D_SensitiveSegment.hxx>
35 #include <SelectMgr_EntityOwner.hxx>
36 #include <SelectMgr_Selection.hxx>
37 #include <Standard_Type.hxx>
38 #include <StdPrs_Curve.hxx>
39 #include <TColgp_Array1OfPnt.hxx>
40 #include <UnitsAPI.hxx>
42 IMPLEMENT_STANDARD_RTTIEXT(AIS_Line,AIS_InteractiveObject)
44 //==================================================================
45 // function: FindLimits
47 //==================================================================
50 static void FindLimits(const Adaptor3d_Curve& aCurve,
51 const Standard_Real aLimit,
55 Standard_Real First = aCurve.FirstParameter();
56 Standard_Real Last = aCurve.LastParameter();
57 Standard_Boolean firstInf = Precision::IsNegativeInfinite(First);
58 Standard_Boolean lastInf = Precision::IsPositiveInfinite(Last);
59 if (firstInf || lastInf) {
60 Standard_Real delta = 1;
61 if (firstInf && lastInf) {
68 } while (P1.Distance(P2) < aLimit);
76 } while (P1.Distance(P2) < aLimit);
84 } while (P1.Distance(P2) < aLimit);
90 //=======================================================================
93 //=======================================================================
94 AIS_Line::AIS_Line(const Handle(Geom_Line)& aComponent):
95 myComponent (aComponent),
96 myLineIsSegment(Standard_False)
101 //=======================================================================
102 //function : AIS_Line
104 //=======================================================================
105 AIS_Line::AIS_Line(const Handle(Geom_Point)& aStartPoint,
106 const Handle(Geom_Point)& aEndPoint):
107 myStartPoint(aStartPoint),
108 myEndPoint(aEndPoint),
109 myLineIsSegment(Standard_True)
112 //=======================================================================
115 //=======================================================================
116 void AIS_Line::Compute(const Handle(PrsMgr_PresentationManager3d)&,
117 const Handle(Prs3d_Presentation)& aPresentation,
118 const Standard_Integer)
120 aPresentation->Clear();
122 aPresentation->SetDisplayPriority(5);
124 if (!myLineIsSegment) ComputeInfiniteLine(aPresentation);
125 else ComputeSegmentLine(aPresentation);
129 void AIS_Line::Compute(const Handle(Prs3d_Projector)& aProjector, const Handle(Geom_Transformation)& aTransformation, const Handle(Prs3d_Presentation)& aPresentation)
131 // Standard_NotImplemented::Raise("AIS_Line::Compute(const Handle(Prs3d_Projector)&, const Handle(Geom_Transformation)&, const Handle(Prs3d_Presentation)&)");
132 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation) ;
135 //=======================================================================
136 //function : ComputeSelection
138 //=======================================================================
140 void AIS_Line::ComputeSelection(const Handle(SelectMgr_Selection)& theSelection,
141 const Standard_Integer theMode)
143 // Do not support selection modes different from 0 currently
147 if (!myLineIsSegment)
149 ComputeInfiniteLineSelection(theSelection);
153 ComputeSegmentLineSelection(theSelection);
158 //=======================================================================
159 //function : SetColor
161 //=======================================================================
163 void AIS_Line::SetColor(const Quantity_NameOfColor aCol)
165 SetColor(Quantity_Color(aCol));
168 void AIS_Line::SetColor(const Quantity_Color &aCol)
170 hasOwnColor=Standard_True;
173 Standard_Real WW = HasWidth()? myOwnWidth:
174 myDrawer->HasLink() ?
175 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Line) : 1.;
177 if (!myDrawer->HasOwnLineAspect ())
178 myDrawer->SetLineAspect (new Prs3d_LineAspect(aCol,Aspect_TOL_SOLID,WW));
180 myDrawer->LineAspect()->SetColor(aCol);
184 //=======================================================================
185 //function : UnsetColor
187 //=======================================================================
188 void AIS_Line::UnsetColor()
190 hasOwnColor = Standard_False;
192 Handle(Prs3d_LineAspect) NullAsp;
194 if (!HasWidth()) myDrawer->SetLineAspect(NullAsp);
196 Quantity_Color CC = Quantity_NOC_YELLOW;
197 if( HasColor() ) CC = myOwnColor;
198 else if (myDrawer->HasLink()) AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Line, CC);
199 myDrawer->LineAspect()->SetColor(CC);
204 //=======================================================================
205 //function : SetWidth
207 //=======================================================================
208 void AIS_Line::SetWidth(const Standard_Real aValue)
212 if (!myDrawer->HasOwnLineAspect ()) {
213 Quantity_Color CC = Quantity_NOC_YELLOW;
214 if( HasColor() ) CC = myOwnColor;
215 else if(myDrawer->HasLink()) AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Line, CC);
216 myDrawer->SetLineAspect (new Prs3d_LineAspect (CC, Aspect_TOL_SOLID, aValue));
218 myDrawer->LineAspect()->SetWidth(aValue);
222 //=======================================================================
223 //function : UnsetWidth
225 //=======================================================================
226 void AIS_Line::UnsetWidth()
228 Handle(Prs3d_LineAspect) NullAsp;
230 if (!HasColor()) myDrawer->SetLineAspect(NullAsp);
232 Standard_Real WW = myDrawer->HasLink() ?
233 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Line) : 1.;
234 myDrawer->LineAspect()->SetWidth(WW);
239 //=======================================================================
240 //function : ComputeInfiniteLine
242 //=======================================================================
243 void AIS_Line::ComputeInfiniteLine( const Handle(Prs3d_Presentation)& aPresentation)
245 GeomAdaptor_Curve curv(myComponent);
246 StdPrs_Curve::Add(aPresentation,curv,myDrawer);
248 //pas de prise en compte lors du FITALL
249 aPresentation->SetInfiniteState (Standard_True);
252 //=======================================================================
253 //function : ComputeSegmentLine
255 //=======================================================================
256 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 StdPrs_Curve::Add(aPresentation,curv,myDrawer);
269 //=======================================================================
270 //function : ComputeInfiniteLineSelection
272 //=======================================================================
274 void AIS_Line::ComputeInfiniteLineSelection(const Handle(SelectMgr_Selection)& aSelection)
277 /* // on calcule les points min max a partir desquels on cree un segment sensible...
278 GeomAdaptor_Curve curv(myComponent);
280 FindLimits(curv,myDrawer->MaximalParameterValue(),P1,P2);
282 const gp_Dir& thedir = myComponent->Position().Direction();
283 const gp_Pnt& loc = myComponent->Position().Location();
284 const gp_XYZ& dir_xyz = thedir.XYZ();
285 const gp_XYZ& loc_xyz = loc.XYZ();
286 //POP Standard_Real aLength = UnitsAPI::CurrentToLS (250000. ,"LENGTH");
287 Standard_Real aLength = UnitsAPI::AnyToLS (250000. ,"mm");
288 gp_Pnt P1 = loc_xyz + aLength*dir_xyz;
289 gp_Pnt P2 = loc_xyz - aLength*dir_xyz;
290 Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this,5);
291 Handle(Select3D_SensitiveSegment) seg = new Select3D_SensitiveSegment(eown,P1,P2);
292 aSelection->Add(seg);
294 //=======================================================================
295 //function : ComputeSegmentLineSelection
297 //=======================================================================
299 void AIS_Line::ComputeSegmentLineSelection(const Handle(SelectMgr_Selection)& aSelection)
303 Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this,5);
304 Handle(Select3D_SensitiveSegment) seg = new Select3D_SensitiveSegment(eown,
307 aSelection->Add(seg);
310 //=======================================================================
312 //purpose : to avoid warning
313 //=======================================================================
314 void AIS_Line::Compute(const Handle(Prs3d_Projector)&,
315 const Handle(Prs3d_Presentation)&)