0024837: Visualization - revise design and implementation of connected Interactive...
[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_Drawer.hxx>
21 #include <AIS_InteractiveContext.hxx>
22 #include <Geom_Line.hxx>
23 #include <gp_Lin.hxx>
24 #include <TNaming_Tool.hxx>
25 #include <TNaming_NamedShape.hxx>
26 #include <TopoDS_Shape.hxx>
27
28
29
30 //=======================================================================
31 //function :
32 //purpose  : 
33 //=======================================================================
34 TPrsStd_AxisDriver::TPrsStd_AxisDriver()
35 {
36 }
37
38
39 //=======================================================================
40 //function :
41 //purpose  : 
42 //=======================================================================
43 Standard_Boolean TPrsStd_AxisDriver::Update (const TDF_Label& aLabel,
44                                             Handle(AIS_InteractiveObject)& anAISObject) 
45 {
46
47   Handle(TDataXtd_Axis) apAxis;
48   if ( !aLabel.FindAttribute(TDataXtd_Axis::GetID(), apAxis) ) {
49     return Standard_False;
50   }
51
52   gp_Lin lin;  
53   Handle(TNaming_NamedShape) NS;
54   if(aLabel.FindAttribute(TNaming_NamedShape::GetID(),NS)){
55     if(TNaming_Tool::GetShape(NS).IsNull()){
56       return Standard_False;
57     }
58   }
59   
60   Handle(AIS_Axis) aistrihed;
61   if (TDataXtd_Geometry::Line(aLabel,lin)) {
62     Handle(Geom_Line) apt = new Geom_Line (lin);
63     
64     //  Update de l'AIS
65     if (anAISObject.IsNull())
66       aistrihed = new AIS_Axis(apt);
67     else {
68       aistrihed = Handle(AIS_Axis)::DownCast(anAISObject);
69       if (aistrihed.IsNull()) 
70         aistrihed = new AIS_Axis(apt);
71       else {
72         aistrihed->SetComponent(apt);
73         aistrihed->ResetTransformation();
74         aistrihed->SetToUpdate();
75         aistrihed->UpdateSelection();
76       }
77     }
78     anAISObject = aistrihed;
79     return Standard_True;
80   }
81   return Standard_False;
82 }
83