0025773: Visualization - remove AIS_Drawer class and transfer its Link() logic to...
[occt.git] / src / TPrsStd / TPrsStd_AxisDriver.cxx
1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14 #include <TPrsStd_AxisDriver.ixx>
15
16 #include <TDF_Label.hxx>
17 #include <TDataXtd_Axis.hxx>
18 #include <TDataXtd_Geometry.hxx>
19 #include <AIS_Axis.hxx>
20 #include <AIS_InteractiveContext.hxx>
21 #include <Geom_Line.hxx>
22 #include <gp_Lin.hxx>
23 #include <TNaming_Tool.hxx>
24 #include <TNaming_NamedShape.hxx>
25 #include <TopoDS_Shape.hxx>
26
27
28
29 //=======================================================================
30 //function :
31 //purpose  : 
32 //=======================================================================
33 TPrsStd_AxisDriver::TPrsStd_AxisDriver()
34 {
35 }
36
37
38 //=======================================================================
39 //function :
40 //purpose  : 
41 //=======================================================================
42 Standard_Boolean TPrsStd_AxisDriver::Update (const TDF_Label& aLabel,
43                                             Handle(AIS_InteractiveObject)& anAISObject) 
44 {
45
46   Handle(TDataXtd_Axis) apAxis;
47   if ( !aLabel.FindAttribute(TDataXtd_Axis::GetID(), apAxis) ) {
48     return Standard_False;
49   }
50
51   gp_Lin lin;  
52   Handle(TNaming_NamedShape) NS;
53   if(aLabel.FindAttribute(TNaming_NamedShape::GetID(),NS)){
54     if(TNaming_Tool::GetShape(NS).IsNull()){
55       return Standard_False;
56     }
57   }
58   
59   Handle(AIS_Axis) aistrihed;
60   if (TDataXtd_Geometry::Line(aLabel,lin)) {
61     Handle(Geom_Line) apt = new Geom_Line (lin);
62     
63     //  Update de l'AIS
64     if (anAISObject.IsNull())
65       aistrihed = new AIS_Axis(apt);
66     else {
67       aistrihed = Handle(AIS_Axis)::DownCast(anAISObject);
68       if (aistrihed.IsNull()) 
69         aistrihed = new AIS_Axis(apt);
70       else {
71         aistrihed->SetComponent(apt);
72         aistrihed->ResetTransformation();
73         aistrihed->SetToUpdate();
74         aistrihed->UpdateSelection();
75       }
76     }
77     anAISObject = aistrihed;
78     return Standard_True;
79   }
80   return Standard_False;
81 }
82