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 <Handle_Geom_Line.hxx>
35 #include <Quantity_Color.hxx>
36 #include <AIS_GraphicTool.hxx>
37 #include <UnitsAPI.hxx>
38 //==================================================================
39 // function: FindLimits
41 //==================================================================
44 static void FindLimits(const Adaptor3d_Curve& aCurve,
45 const Standard_Real aLimit,
49 Standard_Real First = aCurve.FirstParameter();
50 Standard_Real Last = aCurve.LastParameter();
51 Standard_Boolean firstInf = Precision::IsNegativeInfinite(First);
52 Standard_Boolean lastInf = Precision::IsPositiveInfinite(Last);
55 if (firstInf || lastInf) {
56 Standard_Real delta = 1;
57 if (firstInf && lastInf) {
64 } while (P1.Distance(P2) < aLimit);
72 } while (P1.Distance(P2) < aLimit);
80 } while (P1.Distance(P2) < aLimit);
87 //=======================================================================
90 //=======================================================================
91 AIS_Line::AIS_Line(const Handle(Geom_Line)& aComponent):
92 myComponent (aComponent),
93 myLineIsSegment(Standard_False)
98 //=======================================================================
101 //=======================================================================
102 AIS_Line::AIS_Line(const Handle(Geom_Point)& aStartPoint,
103 const Handle(Geom_Point)& aEndPoint):
104 myStartPoint(aStartPoint),
105 myEndPoint(aEndPoint),
106 myLineIsSegment(Standard_True)
109 //=======================================================================
112 //=======================================================================
113 void AIS_Line::Compute(const Handle(PrsMgr_PresentationManager3d)&,
114 const Handle(Prs3d_Presentation)& aPresentation,
115 const Standard_Integer)
117 aPresentation->Clear();
119 aPresentation->SetDisplayPriority(5);
121 if (!myLineIsSegment) ComputeInfiniteLine(aPresentation);
122 else ComputeSegmentLine(aPresentation);
126 void AIS_Line::Compute(const Handle_Prs3d_Projector& aProjector, const Handle_Geom_Transformation& aTransformation, const Handle_Prs3d_Presentation& aPresentation)
128 // Standard_NotImplemented::Raise("AIS_Line::Compute(const Handle_Prs3d_Projector&, const Handle_Geom_Transformation&, const Handle_Prs3d_Presentation&)");
129 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation) ;
132 //=======================================================================
133 //function : ComputeSelection
135 //=======================================================================
137 void AIS_Line::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
138 const Standard_Integer)
141 if (!myLineIsSegment) ComputeInfiniteLineSelection(aSelection);
142 else ComputeSegmentLineSelection(aSelection);
147 //=======================================================================
148 //function : SetColor
150 //=======================================================================
152 void AIS_Line::SetColor(const Quantity_NameOfColor aCol)
154 SetColor(Quantity_Color(aCol));
157 void AIS_Line::SetColor(const Quantity_Color &aCol)
159 hasOwnColor=Standard_True;
162 Standard_Real WW = HasWidth()? myOwnWidth:
163 AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Line);
165 if (!myDrawer->HasLineAspect ())
166 myDrawer->SetLineAspect (new Prs3d_LineAspect(aCol,Aspect_TOL_SOLID,WW));
168 myDrawer->LineAspect()->SetColor(aCol);
172 //=======================================================================
173 //function : UnsetColor
175 //=======================================================================
176 void AIS_Line::UnsetColor()
178 hasOwnColor = Standard_False;
180 Handle(Prs3d_LineAspect) NullAsp;
182 if (!HasWidth()) myDrawer->SetLineAspect(NullAsp);
185 if( HasColor() ) CC = myOwnColor;
186 else AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line,CC);
187 myDrawer->LineAspect()->SetColor(CC);
192 //=======================================================================
193 //function : SetWidth
195 //=======================================================================
196 void AIS_Line::SetWidth(const Standard_Real aValue)
200 if (!myDrawer->HasLineAspect ()) {
202 if( HasColor() ) CC = myOwnColor;
203 else AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line,CC);
204 myDrawer->SetLineAspect (new Prs3d_LineAspect(CC,Aspect_TOL_SOLID,aValue));
206 myDrawer->LineAspect()->SetWidth(aValue);
210 //=======================================================================
211 //function : UnsetWidth
213 //=======================================================================
214 void AIS_Line::UnsetWidth()
216 Handle(Prs3d_LineAspect) NullAsp;
218 if (!HasColor()) myDrawer->SetLineAspect(NullAsp);
220 Standard_Real WW = AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Line);
221 myDrawer->LineAspect()->SetWidth(WW);
226 //=======================================================================
227 //function : ComputeInfiniteLine
229 //=======================================================================
230 void AIS_Line::ComputeInfiniteLine( const Handle(Prs3d_Presentation)& aPresentation)
232 GeomAdaptor_Curve curv(myComponent);
233 StdPrs_Curve::Add(aPresentation,curv,myDrawer);
235 //pas de prise en compte lors du FITALL
236 aPresentation->SetInfiniteState (Standard_True);
239 //=======================================================================
240 //function : ComputeSegmentLine
242 //=======================================================================
243 void AIS_Line::ComputeSegmentLine( const Handle(Prs3d_Presentation)& aPresentation)
245 gp_Pnt P1 = myStartPoint->Pnt();
246 gp_Pnt P2 = myEndPoint->Pnt();
248 myComponent = new Geom_Line(P1,gp_Dir(P2.XYZ()-P1.XYZ()));
250 Standard_Real dist = P1.Distance(P2);
251 GeomAdaptor_Curve curv(myComponent,0.,dist);
252 StdPrs_Curve::Add(aPresentation,curv,myDrawer);
256 //=======================================================================
257 //function : ComputeInfiniteLineSelection
259 //=======================================================================
261 void AIS_Line::ComputeInfiniteLineSelection(const Handle(SelectMgr_Selection)& aSelection)
264 /* // on calcule les points min max a partir desquels on cree un segment sensible...
265 GeomAdaptor_Curve curv(myComponent);
267 FindLimits(curv,myDrawer->MaximalParameterValue(),P1,P2);
269 const gp_Dir& thedir = myComponent->Position().Direction();
270 const gp_Pnt& loc = myComponent->Position().Location();
271 const gp_XYZ& dir_xyz = thedir.XYZ();
272 const gp_XYZ& loc_xyz = loc.XYZ();
273 //POP Standard_Real aLength = UnitsAPI::CurrentToLS (250000. ,"LENGTH");
274 Standard_Real aLength = UnitsAPI::AnyToLS (250000. ,"mm");
275 gp_Pnt P1 = loc_xyz + aLength*dir_xyz;
276 gp_Pnt P2 = loc_xyz - aLength*dir_xyz;
277 Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this,5);
278 Handle(Select3D_SensitiveSegment) seg = new Select3D_SensitiveSegment(eown,P1,P2);
279 aSelection->Add(seg);
281 //=======================================================================
282 //function : ComputeSegmentLineSelection
284 //=======================================================================
286 void AIS_Line::ComputeSegmentLineSelection(const Handle(SelectMgr_Selection)& aSelection)
290 Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this,5);
291 Handle(Select3D_SensitiveSegment) seg = new Select3D_SensitiveSegment(eown,
294 aSelection->Add(seg);
297 //=======================================================================
299 //purpose : to avoid warning
300 //=======================================================================
301 void AIS_Line::Compute(const Handle(Prs3d_Projector)&,
302 const Handle(Prs3d_Presentation)&)