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