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 <Geom_Transformation.hxx>
25 #include <GeomAdaptor_Curve.hxx>
26 #include <Graphic3d_AspectLine3d.hxx>
27 #include <Graphic3d_Structure.hxx>
28 #include <Precision.hxx>
29 #include <Prs3d_Drawer.hxx>
30 #include <Prs3d_LineAspect.hxx>
31 #include <Prs3d_Presentation.hxx>
32 #include <Quantity_Color.hxx>
33 #include <Select3D_SensitiveSegment.hxx>
34 #include <SelectMgr_EntityOwner.hxx>
35 #include <SelectMgr_Selection.hxx>
36 #include <Standard_Type.hxx>
37 #include <StdPrs_Curve.hxx>
38 #include <TColgp_Array1OfPnt.hxx>
39 #include <UnitsAPI.hxx>
41 IMPLEMENT_STANDARD_RTTIEXT(AIS_Line,AIS_InteractiveObject)
43 //=======================================================================
46 //=======================================================================
47 AIS_Line::AIS_Line(const Handle(Geom_Line)& aComponent):
48 myComponent (aComponent),
49 myLineIsSegment(Standard_False)
54 //=======================================================================
57 //=======================================================================
58 AIS_Line::AIS_Line(const Handle(Geom_Point)& aStartPoint,
59 const Handle(Geom_Point)& aEndPoint):
60 myStartPoint(aStartPoint),
61 myEndPoint(aEndPoint),
62 myLineIsSegment(Standard_True)
65 //=======================================================================
68 //=======================================================================
69 void AIS_Line::Compute(const Handle(PrsMgr_PresentationManager3d)&,
70 const Handle(Prs3d_Presentation)& aPresentation,
71 const Standard_Integer)
73 aPresentation->SetDisplayPriority(5);
75 if (!myLineIsSegment) ComputeInfiniteLine(aPresentation);
76 else ComputeSegmentLine(aPresentation);
80 //=======================================================================
81 //function : ComputeSelection
83 //=======================================================================
85 void AIS_Line::ComputeSelection(const Handle(SelectMgr_Selection)& theSelection,
86 const Standard_Integer theMode)
88 // Do not support selection modes different from 0 currently
94 ComputeInfiniteLineSelection(theSelection);
98 ComputeSegmentLineSelection(theSelection);
102 //=======================================================================
103 //function : replaceWithNewLineAspect
105 //=======================================================================
106 void AIS_Line::replaceWithNewLineAspect (const Handle(Prs3d_LineAspect)& theAspect)
108 if (!myDrawer->HasLink())
110 myDrawer->SetLineAspect (theAspect);
114 const Handle(Graphic3d_Aspects)& anAspectOld = myDrawer->LineAspect()->Aspect();
115 const Handle(Graphic3d_Aspects)& anAspectNew = !theAspect.IsNull() ? theAspect->Aspect() : myDrawer->Link()->LineAspect()->Aspect();
116 if (anAspectNew != anAspectOld)
118 myDrawer->SetLineAspect (theAspect);
119 Graphic3d_MapOfAspectsToAspects aReplaceMap;
120 aReplaceMap.Bind (anAspectOld, anAspectNew);
121 replaceAspects (aReplaceMap);
125 //=======================================================================
126 //function : SetColor
128 //=======================================================================
129 void AIS_Line::SetColor(const Quantity_Color &aCol)
131 hasOwnColor=Standard_True;
132 myDrawer->SetColor (aCol);
134 Standard_Real WW = HasWidth()? myOwnWidth:
135 myDrawer->HasLink() ?
136 AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Line) : 1.;
138 if (!myDrawer->HasOwnLineAspect())
140 replaceWithNewLineAspect (new Prs3d_LineAspect (aCol, Aspect_TOL_SOLID, WW));
144 myDrawer->LineAspect()->SetColor (aCol);
145 SynchronizeAspects();
150 //=======================================================================
151 //function : UnsetColor
153 //=======================================================================
154 void AIS_Line::UnsetColor()
156 hasOwnColor = Standard_False;
160 replaceWithNewLineAspect (Handle(Prs3d_LineAspect)());
164 Quantity_Color CC = Quantity_NOC_YELLOW;
165 if( HasColor() ) CC = myDrawer->Color();
166 else if (myDrawer->HasLink()) AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Line, CC);
167 myDrawer->LineAspect()->SetColor(CC);
168 myDrawer->SetColor (CC);
169 SynchronizeAspects();
173 //=======================================================================
174 //function : SetWidth
176 //=======================================================================
177 void AIS_Line::SetWidth(const Standard_Real aValue)
179 myOwnWidth = (Standard_ShortReal )aValue;
181 if (!myDrawer->HasOwnLineAspect())
183 Quantity_Color CC = Quantity_NOC_YELLOW;
184 if( HasColor() ) CC = myDrawer->Color();
185 else if(myDrawer->HasLink()) AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Line, CC);
186 replaceWithNewLineAspect (new Prs3d_LineAspect (CC, Aspect_TOL_SOLID, aValue));
190 myDrawer->LineAspect()->SetWidth (aValue);
191 SynchronizeAspects();
196 //=======================================================================
197 //function : UnsetWidth
199 //=======================================================================
200 void AIS_Line::UnsetWidth()
204 replaceWithNewLineAspect (Handle(Prs3d_LineAspect)());
208 Standard_ShortReal WW = myDrawer->HasLink() ? (Standard_ShortReal )AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Line) : 1.0f;
209 myDrawer->LineAspect()->SetWidth (WW);
211 SynchronizeAspects();
215 //=======================================================================
216 //function : ComputeInfiniteLine
218 //=======================================================================
219 void AIS_Line::ComputeInfiniteLine( const Handle(Prs3d_Presentation)& aPresentation)
221 GeomAdaptor_Curve curv(myComponent);
222 StdPrs_Curve::Add(aPresentation,curv,myDrawer);
224 //pas de prise en compte lors du FITALL
225 aPresentation->SetInfiniteState (Standard_True);
228 //=======================================================================
229 //function : ComputeSegmentLine
231 //=======================================================================
232 void AIS_Line::ComputeSegmentLine( const Handle(Prs3d_Presentation)& aPresentation)
234 gp_Pnt P1 = myStartPoint->Pnt();
235 gp_Pnt P2 = myEndPoint->Pnt();
237 myComponent = new Geom_Line(P1,gp_Dir(P2.XYZ()-P1.XYZ()));
239 Standard_Real dist = P1.Distance(P2);
240 GeomAdaptor_Curve curv(myComponent,0.,dist);
241 StdPrs_Curve::Add(aPresentation,curv,myDrawer);
245 //=======================================================================
246 //function : ComputeInfiniteLineSelection
248 //=======================================================================
250 void AIS_Line::ComputeInfiniteLineSelection(const Handle(SelectMgr_Selection)& aSelection)
253 /* // on calcule les points min max a partir desquels on cree un segment sensible...
254 GeomAdaptor_Curve curv(myComponent);
256 FindLimits(curv,myDrawer->MaximalParameterValue(),P1,P2);
258 const gp_Dir& thedir = myComponent->Position().Direction();
259 const gp_Pnt& loc = myComponent->Position().Location();
260 const gp_XYZ& dir_xyz = thedir.XYZ();
261 const gp_XYZ& loc_xyz = loc.XYZ();
262 //POP Standard_Real aLength = UnitsAPI::CurrentToLS (250000. ,"LENGTH");
263 Standard_Real aLength = UnitsAPI::AnyToLS (250000. ,"mm");
264 gp_Pnt P1 = loc_xyz + aLength*dir_xyz;
265 gp_Pnt P2 = loc_xyz - aLength*dir_xyz;
266 Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this,5);
267 Handle(Select3D_SensitiveSegment) seg = new Select3D_SensitiveSegment(eown,P1,P2);
268 aSelection->Add(seg);
270 //=======================================================================
271 //function : ComputeSegmentLineSelection
273 //=======================================================================
275 void AIS_Line::ComputeSegmentLineSelection(const Handle(SelectMgr_Selection)& aSelection)
279 Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this,5);
280 Handle(Select3D_SensitiveSegment) seg = new Select3D_SensitiveSegment(eown,
283 aSelection->Add(seg);