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_PresentationManager)&,
69 const Handle(Prs3d_Presentation)& thePrs,
70 const Standard_Integer )
72 thePrs->SetDisplayPriority (5);
74 if (!myLineIsSegment) { ComputeInfiniteLine (thePrs); }
75 else { ComputeSegmentLine (thePrs); }
78 //=======================================================================
79 //function : ComputeSelection
81 //=======================================================================
83 void AIS_Line::ComputeSelection(const Handle(SelectMgr_Selection)& theSelection,
84 const Standard_Integer theMode)
86 // Do not support selection modes different from 0 currently
92 ComputeInfiniteLineSelection(theSelection);
96 ComputeSegmentLineSelection(theSelection);
100 //=======================================================================
101 //function : replaceWithNewLineAspect
103 //=======================================================================
104 void AIS_Line::replaceWithNewLineAspect (const Handle(Prs3d_LineAspect)& theAspect)
106 if (!myDrawer->HasLink())
108 myDrawer->SetLineAspect (theAspect);
112 const Handle(Graphic3d_Aspects)& anAspectOld = myDrawer->LineAspect()->Aspect();
113 const Handle(Graphic3d_Aspects)& anAspectNew = !theAspect.IsNull() ? theAspect->Aspect() : myDrawer->Link()->LineAspect()->Aspect();
114 if (anAspectNew != anAspectOld)
116 myDrawer->SetLineAspect (theAspect);
117 Graphic3d_MapOfAspectsToAspects aReplaceMap;
118 aReplaceMap.Bind (anAspectOld, anAspectNew);
119 replaceAspects (aReplaceMap);
123 //=======================================================================
124 //function : SetColor
126 //=======================================================================
127 void AIS_Line::SetColor(const Quantity_Color &aCol)
129 hasOwnColor=Standard_True;
130 myDrawer->SetColor (aCol);
132 Standard_Real WW = HasWidth()? myOwnWidth:
133 myDrawer->HasLink() ?
134 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Line) : 1.;
136 if (!myDrawer->HasOwnLineAspect())
138 replaceWithNewLineAspect (new Prs3d_LineAspect (aCol, Aspect_TOL_SOLID, WW));
142 myDrawer->LineAspect()->SetColor (aCol);
143 SynchronizeAspects();
148 //=======================================================================
149 //function : UnsetColor
151 //=======================================================================
152 void AIS_Line::UnsetColor()
154 hasOwnColor = Standard_False;
158 replaceWithNewLineAspect (Handle(Prs3d_LineAspect)());
162 Quantity_Color CC = Quantity_NOC_YELLOW;
163 if( HasColor() ) CC = myDrawer->Color();
164 else if (myDrawer->HasLink()) AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Line, CC);
165 myDrawer->LineAspect()->SetColor(CC);
166 myDrawer->SetColor (CC);
167 SynchronizeAspects();
171 //=======================================================================
172 //function : SetWidth
174 //=======================================================================
175 void AIS_Line::SetWidth(const Standard_Real aValue)
177 myOwnWidth = (Standard_ShortReal )aValue;
179 if (!myDrawer->HasOwnLineAspect())
181 Quantity_Color CC = Quantity_NOC_YELLOW;
182 if( HasColor() ) CC = myDrawer->Color();
183 else if(myDrawer->HasLink()) AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Line, CC);
184 replaceWithNewLineAspect (new Prs3d_LineAspect (CC, Aspect_TOL_SOLID, aValue));
188 myDrawer->LineAspect()->SetWidth (aValue);
189 SynchronizeAspects();
194 //=======================================================================
195 //function : UnsetWidth
197 //=======================================================================
198 void AIS_Line::UnsetWidth()
202 replaceWithNewLineAspect (Handle(Prs3d_LineAspect)());
206 Standard_ShortReal WW = myDrawer->HasLink() ? (Standard_ShortReal )AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Line) : 1.0f;
207 myDrawer->LineAspect()->SetWidth (WW);
209 SynchronizeAspects();
213 //=======================================================================
214 //function : ComputeInfiniteLine
216 //=======================================================================
217 void AIS_Line::ComputeInfiniteLine( const Handle(Prs3d_Presentation)& aPresentation)
219 GeomAdaptor_Curve curv(myComponent);
220 StdPrs_Curve::Add(aPresentation,curv,myDrawer);
222 //pas de prise en compte lors du FITALL
223 aPresentation->SetInfiniteState (Standard_True);
226 //=======================================================================
227 //function : ComputeSegmentLine
229 //=======================================================================
230 void AIS_Line::ComputeSegmentLine( const Handle(Prs3d_Presentation)& aPresentation)
232 gp_Pnt P1 = myStartPoint->Pnt();
233 gp_Pnt P2 = myEndPoint->Pnt();
235 myComponent = new Geom_Line(P1,gp_Dir(P2.XYZ()-P1.XYZ()));
237 Standard_Real dist = P1.Distance(P2);
238 GeomAdaptor_Curve curv(myComponent,0.,dist);
239 StdPrs_Curve::Add(aPresentation,curv,myDrawer);
243 //=======================================================================
244 //function : ComputeInfiniteLineSelection
246 //=======================================================================
248 void AIS_Line::ComputeInfiniteLineSelection(const Handle(SelectMgr_Selection)& aSelection)
251 /* // on calcule les points min max a partir desquels on cree un segment sensible...
252 GeomAdaptor_Curve curv(myComponent);
254 FindLimits(curv,myDrawer->MaximalParameterValue(),P1,P2);
256 const gp_Dir& thedir = myComponent->Position().Direction();
257 const gp_Pnt& loc = myComponent->Position().Location();
258 const gp_XYZ& dir_xyz = thedir.XYZ();
259 const gp_XYZ& loc_xyz = loc.XYZ();
260 //POP Standard_Real aLength = UnitsAPI::CurrentToLS (250000. ,"LENGTH");
261 Standard_Real aLength = UnitsAPI::AnyToLS (250000. ,"mm");
262 gp_Pnt P1 = loc_xyz + aLength*dir_xyz;
263 gp_Pnt P2 = loc_xyz - aLength*dir_xyz;
264 Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this,5);
265 Handle(Select3D_SensitiveSegment) seg = new Select3D_SensitiveSegment(eown,P1,P2);
266 aSelection->Add(seg);
268 //=======================================================================
269 //function : ComputeSegmentLineSelection
271 //=======================================================================
273 void AIS_Line::ComputeSegmentLineSelection(const Handle(SelectMgr_Selection)& aSelection)
277 Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this,5);
278 Handle(Select3D_SensitiveSegment) seg = new Select3D_SensitiveSegment(eown,
281 aSelection->Add(seg);