1 // Created on: 1997-01-21
2 // Created by: Prestataire Christiane ARMAND
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
22 #define GER61351 //GG_171199 Enable to set an object RGB color
23 // instead a restricted object NameOfColor.
25 #include <AIS_Line.ixx>
26 #include <Aspect_TypeOfLine.hxx>
27 #include <Prs3d_Drawer.hxx>
28 #include <Precision.hxx>
29 #include <Prs3d_LineAspect.hxx>
30 #include <Graphic3d_ArrayOfPrimitives.hxx>
31 #include <Graphic3d_AspectLine3d.hxx>
32 #include <Graphic3d_Structure.hxx>
33 #include <TColgp_Array1OfPnt.hxx>
34 #include <SelectMgr_EntityOwner.hxx>
35 #include <Select3D_SensitiveSegment.hxx>
36 #include <StdPrs_Curve.hxx>
37 #include <Geom_Line.hxx>
38 #include <GeomAdaptor_Curve.hxx>
39 #include <AIS_Drawer.hxx>
40 #include <GC_MakeSegment.hxx>
41 #include <Handle_Geom_Line.hxx>
42 #include <Quantity_Color.hxx>
43 #include <AIS_GraphicTool.hxx>
44 #include <UnitsAPI.hxx>
45 //==================================================================
46 // function: FindLimits
48 //==================================================================
51 static void FindLimits(const Adaptor3d_Curve& aCurve,
52 const Standard_Real aLimit,
56 Standard_Real First = aCurve.FirstParameter();
57 Standard_Real Last = aCurve.LastParameter();
58 Standard_Boolean firstInf = Precision::IsNegativeInfinite(First);
59 Standard_Boolean lastInf = Precision::IsPositiveInfinite(Last);
62 if (firstInf || lastInf) {
63 Standard_Real delta = 1;
64 if (firstInf && lastInf) {
71 } while (P1.Distance(P2) < aLimit);
79 } while (P1.Distance(P2) < aLimit);
87 } while (P1.Distance(P2) < aLimit);
94 //=======================================================================
97 //=======================================================================
98 AIS_Line::AIS_Line(const Handle(Geom_Line)& aComponent):
99 myComponent (aComponent),
100 myLineIsSegment(Standard_False)
105 //=======================================================================
106 //function : AIS_Line
108 //=======================================================================
109 AIS_Line::AIS_Line(const Handle(Geom_Point)& aStartPoint,
110 const Handle(Geom_Point)& aEndPoint):
111 myStartPoint(aStartPoint),
112 myEndPoint(aEndPoint),
113 myLineIsSegment(Standard_True)
116 //=======================================================================
119 //=======================================================================
120 void AIS_Line::Compute(const Handle(PrsMgr_PresentationManager3d)&,
121 const Handle(Prs3d_Presentation)& aPresentation,
122 const Standard_Integer)
124 aPresentation->Clear();
126 aPresentation->SetDisplayPriority(5);
128 if (!myLineIsSegment) ComputeInfiniteLine(aPresentation);
129 else ComputeSegmentLine(aPresentation);
133 void AIS_Line::Compute(const Handle_Prs3d_Projector& aProjector, const Handle_Geom_Transformation& aTransformation, const Handle_Prs3d_Presentation& aPresentation)
135 // Standard_NotImplemented::Raise("AIS_Line::Compute(const Handle_Prs3d_Projector&, const Handle_Geom_Transformation&, const Handle_Prs3d_Presentation&)");
136 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation) ;
139 //=======================================================================
140 //function : ComputeSelection
142 //=======================================================================
144 void AIS_Line::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
145 const Standard_Integer)
148 if (!myLineIsSegment) ComputeInfiniteLineSelection(aSelection);
149 else ComputeSegmentLineSelection(aSelection);
154 //=======================================================================
155 //function : SetColor
157 //=======================================================================
159 void AIS_Line::SetColor(const Quantity_NameOfColor aCol)
162 SetColor(Quantity_Color(aCol));
165 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);
195 if( HasColor() ) CC = myOwnColor;
196 else AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line,CC);
198 Quantity_NameOfColor CC =
199 AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line);
202 myDrawer->LineAspect()->SetColor(CC);
207 //=======================================================================
208 //function : SetWidth
210 //=======================================================================
211 void AIS_Line::SetWidth(const Standard_Real aValue)
216 Quantity_NameOfColor CC =
217 HasColor()? myOwnColor : AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line);
220 if (!myDrawer->HasLineAspect ()) {
223 if( HasColor() ) CC = myOwnColor;
224 else AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line,CC);
226 myDrawer->SetLineAspect (new Prs3d_LineAspect(CC,Aspect_TOL_SOLID,aValue));
228 myDrawer->LineAspect()->SetWidth(aValue);
232 //=======================================================================
233 //function : UnsetWidth
235 //=======================================================================
236 void AIS_Line::UnsetWidth()
238 Handle(Prs3d_LineAspect) NullAsp;
240 if (!HasColor()) myDrawer->SetLineAspect(NullAsp);
242 Standard_Real WW = AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Line);
243 myDrawer->LineAspect()->SetWidth(WW);
248 //=======================================================================
249 //function : ComputeInfiniteLine
251 //=======================================================================
252 void AIS_Line::ComputeInfiniteLine( const Handle(Prs3d_Presentation)& aPresentation)
255 GeomAdaptor_Curve curv(myComponent);
256 Standard_Boolean isPrimitiveArraysEnabled = Graphic3d_ArrayOfPrimitives::IsEnable();
257 if(isPrimitiveArraysEnabled) Graphic3d_ArrayOfPrimitives::Disable();
258 StdPrs_Curve::Add(aPresentation,curv,myDrawer);
259 if(isPrimitiveArraysEnabled) Graphic3d_ArrayOfPrimitives::Enable();
261 //pas de prise en compte lors du FITALL
262 aPresentation->SetInfiniteState (Standard_True);
266 //=======================================================================
267 //function : ComputeSegmentLine
269 //=======================================================================
270 void AIS_Line::ComputeSegmentLine( const Handle(Prs3d_Presentation)& aPresentation)
273 gp_Pnt P1 = myStartPoint->Pnt();
274 gp_Pnt P2 = myEndPoint->Pnt();
276 myComponent = new Geom_Line(P1,gp_Dir(P2.XYZ()-P1.XYZ()));
278 Standard_Real dist = P1.Distance(P2);
279 GeomAdaptor_Curve curv(myComponent,0.,dist);
280 Standard_Boolean isPrimitiveArraysEnabled = Graphic3d_ArrayOfPrimitives::IsEnable();
281 if(isPrimitiveArraysEnabled) Graphic3d_ArrayOfPrimitives::Disable();
282 StdPrs_Curve::Add(aPresentation,curv,myDrawer);
283 if(isPrimitiveArraysEnabled) Graphic3d_ArrayOfPrimitives::Enable();
288 //=======================================================================
289 //function : ComputeInfiniteLineSelection
291 //=======================================================================
293 void AIS_Line::ComputeInfiniteLineSelection(const Handle(SelectMgr_Selection)& aSelection)
296 /* // on calcule les points min max a partir desquels on cree un segment sensible...
297 GeomAdaptor_Curve curv(myComponent);
299 FindLimits(curv,myDrawer->MaximalParameterValue(),P1,P2);
301 const gp_Dir& thedir = myComponent->Position().Direction();
302 const gp_Pnt& loc = myComponent->Position().Location();
303 const gp_XYZ& dir_xyz = thedir.XYZ();
304 const gp_XYZ& loc_xyz = loc.XYZ();
305 //POP Standard_Real aLength = UnitsAPI::CurrentToLS (250000. ,"LENGTH");
306 Standard_Real aLength = UnitsAPI::AnyToLS (250000. ,"mm");
307 gp_Pnt P1 = loc_xyz + aLength*dir_xyz;
308 gp_Pnt P2 = loc_xyz - aLength*dir_xyz;
309 Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this,5);
310 Handle(Select3D_SensitiveSegment) seg = new Select3D_SensitiveSegment(eown,P1,P2);
311 aSelection->Add(seg);
313 //=======================================================================
314 //function : ComputeSegmentLineSelection
316 //=======================================================================
318 void AIS_Line::ComputeSegmentLineSelection(const Handle(SelectMgr_Selection)& aSelection)
322 Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this,5);
323 Handle(Select3D_SensitiveSegment) seg = new Select3D_SensitiveSegment(eown,
326 aSelection->Add(seg);
328 //=======================================================================
330 //purpose : to avoid warning
331 //=======================================================================
332 void AIS_Line::Compute(const Handle(PrsMgr_PresentationManager2d)&,
333 const Handle(Graphic2d_GraphicObject)&,
334 const Standard_Integer)
338 //=======================================================================
340 //purpose : to avoid warning
341 //=======================================================================
342 void AIS_Line::Compute(const Handle(Prs3d_Projector)&,
343 const Handle(Prs3d_Presentation)&)