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.
17 //GER61351 //GG_171199 Enable to set an object RGB color instead a restricted object NameOfColor.
19 #include <AIS_Line.ixx>
20 #include <Aspect_TypeOfLine.hxx>
21 #include <Prs3d_Drawer.hxx>
22 #include <Precision.hxx>
23 #include <Prs3d_LineAspect.hxx>
24 #include <Graphic3d_AspectLine3d.hxx>
25 #include <Graphic3d_Structure.hxx>
26 #include <TColgp_Array1OfPnt.hxx>
27 #include <SelectMgr_EntityOwner.hxx>
28 #include <Select3D_SensitiveSegment.hxx>
29 #include <StdPrs_Curve.hxx>
30 #include <Geom_Line.hxx>
31 #include <GeomAdaptor_Curve.hxx>
32 #include <AIS_Drawer.hxx>
33 #include <GC_MakeSegment.hxx>
34 #include <Geom_Line.hxx>
35 #include <Quantity_Color.hxx>
36 #include <AIS_GraphicTool.hxx>
37 #include <UnitsAPI.hxx>
39 //==================================================================
40 // function: FindLimits
42 //==================================================================
45 static void FindLimits(const Adaptor3d_Curve& aCurve,
46 const Standard_Real aLimit,
50 Standard_Real First = aCurve.FirstParameter();
51 Standard_Real Last = aCurve.LastParameter();
52 Standard_Boolean firstInf = Precision::IsNegativeInfinite(First);
53 Standard_Boolean lastInf = Precision::IsPositiveInfinite(Last);
56 if (firstInf || lastInf) {
57 Standard_Real delta = 1;
58 if (firstInf && lastInf) {
65 } while (P1.Distance(P2) < aLimit);
73 } while (P1.Distance(P2) < aLimit);
81 } while (P1.Distance(P2) < aLimit);
88 //=======================================================================
91 //=======================================================================
92 AIS_Line::AIS_Line(const Handle(Geom_Line)& aComponent):
93 myComponent (aComponent),
94 myLineIsSegment(Standard_False)
99 //=======================================================================
100 //function : AIS_Line
102 //=======================================================================
103 AIS_Line::AIS_Line(const Handle(Geom_Point)& aStartPoint,
104 const Handle(Geom_Point)& aEndPoint):
105 myStartPoint(aStartPoint),
106 myEndPoint(aEndPoint),
107 myLineIsSegment(Standard_True)
110 //=======================================================================
113 //=======================================================================
114 void AIS_Line::Compute(const Handle(PrsMgr_PresentationManager3d)&,
115 const Handle(Prs3d_Presentation)& aPresentation,
116 const Standard_Integer)
118 aPresentation->Clear();
120 aPresentation->SetDisplayPriority(5);
122 if (!myLineIsSegment) ComputeInfiniteLine(aPresentation);
123 else ComputeSegmentLine(aPresentation);
127 void AIS_Line::Compute(const Handle_Prs3d_Projector& aProjector, const Handle_Geom_Transformation& aTransformation, const Handle_Prs3d_Presentation& aPresentation)
129 // Standard_NotImplemented::Raise("AIS_Line::Compute(const Handle_Prs3d_Projector&, const Handle_Geom_Transformation&, const Handle_Prs3d_Presentation&)");
130 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation) ;
133 //=======================================================================
134 //function : ComputeSelection
136 //=======================================================================
138 void AIS_Line::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
139 const Standard_Integer)
142 if (!myLineIsSegment) ComputeInfiniteLineSelection(aSelection);
143 else ComputeSegmentLineSelection(aSelection);
148 //=======================================================================
149 //function : SetColor
151 //=======================================================================
153 void AIS_Line::SetColor(const Quantity_NameOfColor aCol)
155 SetColor(Quantity_Color(aCol));
158 void AIS_Line::SetColor(const Quantity_Color &aCol)
160 hasOwnColor=Standard_True;
163 Standard_Real WW = HasWidth()? myOwnWidth:
164 AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Line);
166 if (!myDrawer->HasLineAspect ())
167 myDrawer->SetLineAspect (new Prs3d_LineAspect(aCol,Aspect_TOL_SOLID,WW));
169 myDrawer->LineAspect()->SetColor(aCol);
173 //=======================================================================
174 //function : UnsetColor
176 //=======================================================================
177 void AIS_Line::UnsetColor()
179 hasOwnColor = Standard_False;
181 Handle(Prs3d_LineAspect) NullAsp;
183 if (!HasWidth()) myDrawer->SetLineAspect(NullAsp);
186 if( HasColor() ) CC = myOwnColor;
187 else AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line,CC);
188 myDrawer->LineAspect()->SetColor(CC);
193 //=======================================================================
194 //function : SetWidth
196 //=======================================================================
197 void AIS_Line::SetWidth(const Standard_Real aValue)
201 if (!myDrawer->HasLineAspect ()) {
203 if( HasColor() ) CC = myOwnColor;
204 else AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line,CC);
205 myDrawer->SetLineAspect (new Prs3d_LineAspect(CC,Aspect_TOL_SOLID,aValue));
207 myDrawer->LineAspect()->SetWidth(aValue);
211 //=======================================================================
212 //function : UnsetWidth
214 //=======================================================================
215 void AIS_Line::UnsetWidth()
217 Handle(Prs3d_LineAspect) NullAsp;
219 if (!HasColor()) myDrawer->SetLineAspect(NullAsp);
221 Standard_Real WW = AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Line);
222 myDrawer->LineAspect()->SetWidth(WW);
227 //=======================================================================
228 //function : ComputeInfiniteLine
230 //=======================================================================
231 void AIS_Line::ComputeInfiniteLine( const Handle(Prs3d_Presentation)& aPresentation)
233 GeomAdaptor_Curve curv(myComponent);
234 StdPrs_Curve::Add(aPresentation,curv,myDrawer);
236 //pas de prise en compte lors du FITALL
237 aPresentation->SetInfiniteState (Standard_True);
240 //=======================================================================
241 //function : ComputeSegmentLine
243 //=======================================================================
244 void AIS_Line::ComputeSegmentLine( const Handle(Prs3d_Presentation)& aPresentation)
246 gp_Pnt P1 = myStartPoint->Pnt();
247 gp_Pnt P2 = myEndPoint->Pnt();
249 myComponent = new Geom_Line(P1,gp_Dir(P2.XYZ()-P1.XYZ()));
251 Standard_Real dist = P1.Distance(P2);
252 GeomAdaptor_Curve curv(myComponent,0.,dist);
253 StdPrs_Curve::Add(aPresentation,curv,myDrawer);
257 //=======================================================================
258 //function : ComputeInfiniteLineSelection
260 //=======================================================================
262 void AIS_Line::ComputeInfiniteLineSelection(const Handle(SelectMgr_Selection)& aSelection)
265 /* // on calcule les points min max a partir desquels on cree un segment sensible...
266 GeomAdaptor_Curve curv(myComponent);
268 FindLimits(curv,myDrawer->MaximalParameterValue(),P1,P2);
270 const gp_Dir& thedir = myComponent->Position().Direction();
271 const gp_Pnt& loc = myComponent->Position().Location();
272 const gp_XYZ& dir_xyz = thedir.XYZ();
273 const gp_XYZ& loc_xyz = loc.XYZ();
274 //POP Standard_Real aLength = UnitsAPI::CurrentToLS (250000. ,"LENGTH");
275 Standard_Real aLength = UnitsAPI::AnyToLS (250000. ,"mm");
276 gp_Pnt P1 = loc_xyz + aLength*dir_xyz;
277 gp_Pnt P2 = loc_xyz - aLength*dir_xyz;
278 Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this,5);
279 Handle(Select3D_SensitiveSegment) seg = new Select3D_SensitiveSegment(eown,P1,P2);
280 aSelection->Add(seg);
282 //=======================================================================
283 //function : ComputeSegmentLineSelection
285 //=======================================================================
287 void AIS_Line::ComputeSegmentLineSelection(const Handle(SelectMgr_Selection)& aSelection)
291 Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this,5);
292 Handle(Select3D_SensitiveSegment) seg = new Select3D_SensitiveSegment(eown,
295 aSelection->Add(seg);
298 //=======================================================================
300 //purpose : to avoid warning
301 //=======================================================================
302 void AIS_Line::Compute(const Handle(Prs3d_Projector)&,
303 const Handle(Prs3d_Presentation)&)