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 #include <AIS_Line.hxx>
19 #include <AIS_GraphicTool.hxx>
20 #include <Aspect_TypeOfLine.hxx>
21 #include <GC_MakeSegment.hxx>
22 #include <Geom_Line.hxx>
23 #include <Geom_Point.hxx>
24 #include <GeomAdaptor_Curve.hxx>
25 #include <Graphic3d_AspectLine3d.hxx>
26 #include <Graphic3d_Structure.hxx>
27 #include <Precision.hxx>
28 #include <Prs3d_Drawer.hxx>
29 #include <Prs3d_LineAspect.hxx>
30 #include <Prs3d_Presentation.hxx>
31 #include <Quantity_Color.hxx>
32 #include <Select3D_SensitiveSegment.hxx>
33 #include <SelectMgr_EntityOwner.hxx>
34 #include <SelectMgr_Selection.hxx>
35 #include <Standard_Type.hxx>
36 #include <StdPrs_Curve.hxx>
37 #include <TColgp_Array1OfPnt.hxx>
38 #include <UnitsAPI.hxx>
40 IMPLEMENT_STANDARD_RTTIEXT(AIS_Line,AIS_InteractiveObject)
42 //=======================================================================
45 //=======================================================================
46 AIS_Line::AIS_Line(const Handle(Geom_Line)& aComponent):
47 myComponent (aComponent),
48 myLineIsSegment(Standard_False)
53 //=======================================================================
56 //=======================================================================
57 AIS_Line::AIS_Line(const Handle(Geom_Point)& aStartPoint,
58 const Handle(Geom_Point)& aEndPoint):
59 myStartPoint(aStartPoint),
60 myEndPoint(aEndPoint),
61 myLineIsSegment(Standard_True)
64 //=======================================================================
67 //=======================================================================
68 void AIS_Line::Compute(const Handle(PrsMgr_PresentationManager3d)&,
69 const Handle(Prs3d_Presentation)& aPresentation,
70 const Standard_Integer)
72 aPresentation->SetDisplayPriority(5);
74 if (!myLineIsSegment) ComputeInfiniteLine(aPresentation);
75 else ComputeSegmentLine(aPresentation);
79 //=======================================================================
80 //function : ComputeSelection
82 //=======================================================================
84 void AIS_Line::ComputeSelection(const Handle(SelectMgr_Selection)& theSelection,
85 const Standard_Integer theMode)
87 // Do not support selection modes different from 0 currently
93 ComputeInfiniteLineSelection(theSelection);
97 ComputeSegmentLineSelection(theSelection);
101 //=======================================================================
102 //function : replaceWithNewLineAspect
104 //=======================================================================
105 void AIS_Line::replaceWithNewLineAspect (const Handle(Prs3d_LineAspect)& theAspect)
107 if (!myDrawer->HasLink())
109 myDrawer->SetLineAspect (theAspect);
113 const Handle(Graphic3d_Aspects)& anAspectOld = myDrawer->LineAspect()->Aspect();
114 const Handle(Graphic3d_Aspects)& anAspectNew = !theAspect.IsNull() ? theAspect->Aspect() : myDrawer->Link()->LineAspect()->Aspect();
115 if (anAspectNew != anAspectOld)
117 myDrawer->SetLineAspect (theAspect);
118 Graphic3d_MapOfAspectsToAspects aReplaceMap;
119 aReplaceMap.Bind (anAspectOld, anAspectNew);
120 replaceAspects (aReplaceMap);
124 //=======================================================================
125 //function : SetColor
127 //=======================================================================
128 void AIS_Line::SetColor(const Quantity_Color &aCol)
130 hasOwnColor=Standard_True;
131 myDrawer->SetColor (aCol);
133 Standard_Real WW = HasWidth()? myOwnWidth:
134 myDrawer->HasLink() ?
135 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Line) : 1.;
137 if (!myDrawer->HasOwnLineAspect())
139 replaceWithNewLineAspect (new Prs3d_LineAspect (aCol, Aspect_TOL_SOLID, WW));
143 myDrawer->LineAspect()->SetColor (aCol);
144 SynchronizeAspects();
149 //=======================================================================
150 //function : UnsetColor
152 //=======================================================================
153 void AIS_Line::UnsetColor()
155 hasOwnColor = Standard_False;
159 replaceWithNewLineAspect (Handle(Prs3d_LineAspect)());
163 Quantity_Color CC = Quantity_NOC_YELLOW;
164 if( HasColor() ) CC = myDrawer->Color();
165 else if (myDrawer->HasLink()) AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Line, CC);
166 myDrawer->LineAspect()->SetColor(CC);
167 myDrawer->SetColor (CC);
168 SynchronizeAspects();
172 //=======================================================================
173 //function : SetWidth
175 //=======================================================================
176 void AIS_Line::SetWidth(const Standard_Real aValue)
178 myOwnWidth = (Standard_ShortReal )aValue;
180 if (!myDrawer->HasOwnLineAspect())
182 Quantity_Color CC = Quantity_NOC_YELLOW;
183 if( HasColor() ) CC = myDrawer->Color();
184 else if(myDrawer->HasLink()) AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Line, CC);
185 replaceWithNewLineAspect (new Prs3d_LineAspect (CC, Aspect_TOL_SOLID, aValue));
189 myDrawer->LineAspect()->SetWidth (aValue);
190 SynchronizeAspects();
195 //=======================================================================
196 //function : UnsetWidth
198 //=======================================================================
199 void AIS_Line::UnsetWidth()
203 replaceWithNewLineAspect (Handle(Prs3d_LineAspect)());
207 Standard_ShortReal WW = myDrawer->HasLink() ? (Standard_ShortReal )AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Line) : 1.0f;
208 myDrawer->LineAspect()->SetWidth (WW);
210 SynchronizeAspects();
214 //=======================================================================
215 //function : ComputeInfiniteLine
217 //=======================================================================
218 void AIS_Line::ComputeInfiniteLine( const Handle(Prs3d_Presentation)& aPresentation)
220 GeomAdaptor_Curve curv(myComponent);
221 StdPrs_Curve::Add(aPresentation,curv,myDrawer);
223 //pas de prise en compte lors du FITALL
224 aPresentation->SetInfiniteState (Standard_True);
227 //=======================================================================
228 //function : ComputeSegmentLine
230 //=======================================================================
231 void AIS_Line::ComputeSegmentLine( const Handle(Prs3d_Presentation)& aPresentation)
233 gp_Pnt P1 = myStartPoint->Pnt();
234 gp_Pnt P2 = myEndPoint->Pnt();
236 myComponent = new Geom_Line(P1,gp_Dir(P2.XYZ()-P1.XYZ()));
238 Standard_Real dist = P1.Distance(P2);
239 GeomAdaptor_Curve curv(myComponent,0.,dist);
240 StdPrs_Curve::Add(aPresentation,curv,myDrawer);
244 //=======================================================================
245 //function : ComputeInfiniteLineSelection
247 //=======================================================================
249 void AIS_Line::ComputeInfiniteLineSelection(const Handle(SelectMgr_Selection)& aSelection)
252 /* // on calcule les points min max a partir desquels on cree un segment sensible...
253 GeomAdaptor_Curve curv(myComponent);
255 FindLimits(curv,myDrawer->MaximalParameterValue(),P1,P2);
257 const gp_Dir& thedir = myComponent->Position().Direction();
258 const gp_Pnt& loc = myComponent->Position().Location();
259 const gp_XYZ& dir_xyz = thedir.XYZ();
260 const gp_XYZ& loc_xyz = loc.XYZ();
261 //POP Standard_Real aLength = UnitsAPI::CurrentToLS (250000. ,"LENGTH");
262 Standard_Real aLength = UnitsAPI::AnyToLS (250000. ,"mm");
263 gp_Pnt P1 = loc_xyz + aLength*dir_xyz;
264 gp_Pnt P2 = loc_xyz - aLength*dir_xyz;
265 Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this,5);
266 Handle(Select3D_SensitiveSegment) seg = new Select3D_SensitiveSegment(eown,P1,P2);
267 aSelection->Add(seg);
269 //=======================================================================
270 //function : ComputeSegmentLineSelection
272 //=======================================================================
274 void AIS_Line::ComputeSegmentLineSelection(const Handle(SelectMgr_Selection)& aSelection)
278 Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this,5);
279 Handle(Select3D_SensitiveSegment) seg = new Select3D_SensitiveSegment(eown,
282 aSelection->Add(seg);