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)& theSelection,
139 const Standard_Integer theMode)
141 // Do not support selection modes different from 0 currently
145 if (!myLineIsSegment)
147 ComputeInfiniteLineSelection(theSelection);
151 ComputeSegmentLineSelection(theSelection);
156 //=======================================================================
157 //function : SetColor
159 //=======================================================================
161 void AIS_Line::SetColor(const Quantity_NameOfColor aCol)
163 SetColor(Quantity_Color(aCol));
166 void AIS_Line::SetColor(const Quantity_Color &aCol)
168 hasOwnColor=Standard_True;
171 Standard_Real WW = HasWidth()? myOwnWidth:
172 AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Line);
174 if (!myDrawer->HasLineAspect ())
175 myDrawer->SetLineAspect (new Prs3d_LineAspect(aCol,Aspect_TOL_SOLID,WW));
177 myDrawer->LineAspect()->SetColor(aCol);
181 //=======================================================================
182 //function : UnsetColor
184 //=======================================================================
185 void AIS_Line::UnsetColor()
187 hasOwnColor = Standard_False;
189 Handle(Prs3d_LineAspect) NullAsp;
191 if (!HasWidth()) myDrawer->SetLineAspect(NullAsp);
194 if( HasColor() ) CC = myOwnColor;
195 else AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line,CC);
196 myDrawer->LineAspect()->SetColor(CC);
201 //=======================================================================
202 //function : SetWidth
204 //=======================================================================
205 void AIS_Line::SetWidth(const Standard_Real aValue)
209 if (!myDrawer->HasLineAspect ()) {
211 if( HasColor() ) CC = myOwnColor;
212 else AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line,CC);
213 myDrawer->SetLineAspect (new Prs3d_LineAspect(CC,Aspect_TOL_SOLID,aValue));
215 myDrawer->LineAspect()->SetWidth(aValue);
219 //=======================================================================
220 //function : UnsetWidth
222 //=======================================================================
223 void AIS_Line::UnsetWidth()
225 Handle(Prs3d_LineAspect) NullAsp;
227 if (!HasColor()) myDrawer->SetLineAspect(NullAsp);
229 Standard_Real WW = AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Line);
230 myDrawer->LineAspect()->SetWidth(WW);
235 //=======================================================================
236 //function : ComputeInfiniteLine
238 //=======================================================================
239 void AIS_Line::ComputeInfiniteLine( const Handle(Prs3d_Presentation)& aPresentation)
241 GeomAdaptor_Curve curv(myComponent);
242 StdPrs_Curve::Add(aPresentation,curv,myDrawer);
244 //pas de prise en compte lors du FITALL
245 aPresentation->SetInfiniteState (Standard_True);
248 //=======================================================================
249 //function : ComputeSegmentLine
251 //=======================================================================
252 void AIS_Line::ComputeSegmentLine( const Handle(Prs3d_Presentation)& aPresentation)
254 gp_Pnt P1 = myStartPoint->Pnt();
255 gp_Pnt P2 = myEndPoint->Pnt();
257 myComponent = new Geom_Line(P1,gp_Dir(P2.XYZ()-P1.XYZ()));
259 Standard_Real dist = P1.Distance(P2);
260 GeomAdaptor_Curve curv(myComponent,0.,dist);
261 StdPrs_Curve::Add(aPresentation,curv,myDrawer);
265 //=======================================================================
266 //function : ComputeInfiniteLineSelection
268 //=======================================================================
270 void AIS_Line::ComputeInfiniteLineSelection(const Handle(SelectMgr_Selection)& aSelection)
273 /* // on calcule les points min max a partir desquels on cree un segment sensible...
274 GeomAdaptor_Curve curv(myComponent);
276 FindLimits(curv,myDrawer->MaximalParameterValue(),P1,P2);
278 const gp_Dir& thedir = myComponent->Position().Direction();
279 const gp_Pnt& loc = myComponent->Position().Location();
280 const gp_XYZ& dir_xyz = thedir.XYZ();
281 const gp_XYZ& loc_xyz = loc.XYZ();
282 //POP Standard_Real aLength = UnitsAPI::CurrentToLS (250000. ,"LENGTH");
283 Standard_Real aLength = UnitsAPI::AnyToLS (250000. ,"mm");
284 gp_Pnt P1 = loc_xyz + aLength*dir_xyz;
285 gp_Pnt P2 = loc_xyz - aLength*dir_xyz;
286 Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this,5);
287 Handle(Select3D_SensitiveSegment) seg = new Select3D_SensitiveSegment(eown,P1,P2);
288 aSelection->Add(seg);
290 //=======================================================================
291 //function : ComputeSegmentLineSelection
293 //=======================================================================
295 void AIS_Line::ComputeSegmentLineSelection(const Handle(SelectMgr_Selection)& aSelection)
299 Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this,5);
300 Handle(Select3D_SensitiveSegment) seg = new Select3D_SensitiveSegment(eown,
303 aSelection->Add(seg);
306 //=======================================================================
308 //purpose : to avoid warning
309 //=======================================================================
310 void AIS_Line::Compute(const Handle(Prs3d_Projector)&,
311 const Handle(Prs3d_Presentation)&)