0026199: Visualization - use NCollection_IndexedMap instead of NCollection_Sequence...
[occt.git] / src / TPrsStd / TPrsStd_GeometryDriver.cxx
1 // Created on: 1999-09-30
2 // Created by: Sergey RUIN
3 // Copyright (c) 1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <TPrsStd_GeometryDriver.ixx>
18 #include <TDataXtd.hxx>
19 #include <TDF_Label.hxx>
20 #include <TNaming_NamedShape.hxx>
21 #include <TNaming_Tool.hxx>
22 #include <TDataXtd_Geometry.hxx>
23 #include <Geom_CartesianPoint.hxx>
24 #include <Geom_Line.hxx>
25 #include <Geom_Circle.hxx>
26 #include <AIS_Line.hxx>
27 #include <AIS_Point.hxx>
28 #include <AIS_Circle.hxx>
29 #include <AIS_Shape.hxx>
30 #include <AIS_InteractiveContext.hxx>
31 #include <gp_Pnt.hxx>
32 #include <gp_Lin.hxx>
33 #include <gp_Circ.hxx>
34 #include <gp_Elips.hxx>
35 #include <BRepBuilderAPI_MakeEdge.hxx>
36 #include <TopoDS_Shape.hxx>
37 #include <TopoDS_Edge.hxx>
38
39
40 //=======================================================================
41 //function :
42 //purpose  : 
43 //=======================================================================
44 TPrsStd_GeometryDriver::TPrsStd_GeometryDriver()
45 {
46 }
47
48
49 //=======================================================================
50 //function :
51 //purpose  : 
52 //=======================================================================
53 Standard_Boolean TPrsStd_GeometryDriver::Update(const TDF_Label& aLabel,
54                                                Handle(AIS_InteractiveObject)& anAISObject) 
55 {
56   Handle(TDataXtd_Geometry) aGeom;
57   Handle(TNaming_NamedShape) NS;
58   TDataXtd_GeometryEnum GeomType;
59
60   if (!aLabel.FindAttribute(TDataXtd_Geometry::GetID(), aGeom)) {
61     if(aLabel.FindAttribute(TNaming_NamedShape::GetID(), NS) ) {
62       GeomType = TDataXtd_Geometry::Type(aLabel);
63     }
64     else {
65       return Standard_False; 
66     }
67   }
68   else {
69     GeomType = aGeom->GetType();
70   }
71   
72   switch (GeomType)  {
73   case  TDataXtd_POINT   :
74     {
75       gp_Pnt pt; 
76       if (!TDataXtd_Geometry::Point(aLabel,pt)) return Standard_False;
77       Handle(Geom_Point) apt = new Geom_CartesianPoint(pt);
78       Handle(AIS_Point) ais1;
79       if( anAISObject.IsNull() ) ais1 = new AIS_Point(apt);
80       else {    
81         ais1 = Handle(AIS_Point)::DownCast(anAISObject);
82         if (ais1.IsNull()) 
83           ais1 = new AIS_Point(apt);
84         else {
85           ais1->SetComponent(apt);
86           ais1->ResetTransformation();
87           ais1->SetToUpdate();
88           ais1->UpdateSelection();
89         }
90         
91       }
92       anAISObject = ais1;
93       anAISObject->SetColor(Quantity_NOC_RED);
94     }
95   break;
96   case  TDataXtd_LINE   :
97     {
98       gp_Lin ln; 
99       if (!TDataXtd_Geometry::Line(aLabel,ln)) return Standard_False;
100       Handle(Geom_Line) aln = new Geom_Line(ln);
101       Handle(AIS_Line) ais2;
102       if( anAISObject.IsNull() ) ais2 = new AIS_Line(aln);
103       else {
104         ais2 = Handle(AIS_Line)::DownCast(anAISObject);
105         if (ais2.IsNull()) 
106           ais2 = new AIS_Line(aln);
107         else {
108           ais2->SetLine(aln);
109           ais2->ResetTransformation();
110           ais2->SetToUpdate();
111           ais2->UpdateSelection();
112         }
113       }
114       anAISObject = ais2;
115       anAISObject->SetColor(Quantity_NOC_RED);
116       anAISObject->SetInfiniteState(Standard_True);
117       break;
118     }
119   case  TDataXtd_CIRCLE   :
120     {
121       Handle(AIS_Line) ais2;
122       gp_Circ cir; 
123       if (!TDataXtd_Geometry::Circle(aLabel,cir)) return Standard_False; 
124       Handle(Geom_Circle) acir = new Geom_Circle(cir);
125       Handle(AIS_Circle) ais3;
126       if (anAISObject.IsNull()) ais3 = new AIS_Circle(acir);
127       else {
128         ais3 = Handle(AIS_Circle)::DownCast(anAISObject);
129         if (ais3.IsNull()) 
130           ais3 = new AIS_Circle(acir);
131         else {
132           ais3->SetCircle(acir);
133           ais3->ResetTransformation();
134           ais3->SetToUpdate();
135           ais3->UpdateSelection();
136         }
137       }
138       anAISObject = ais3;
139       anAISObject->SetColor(Quantity_NOC_RED);
140       break;
141     }
142   case  TDataXtd_ELLIPSE   :
143     {
144       gp_Elips elp; 
145       if (!TDataXtd_Geometry::Ellipse(aLabel, elp)) return Standard_False;
146       BRepBuilderAPI_MakeEdge mkEdge(elp);
147       if( !mkEdge.IsDone() ) return Standard_False;
148       Handle(AIS_Shape) ais;
149       if (anAISObject.IsNull()) ais = new AIS_Shape(mkEdge);
150       else {
151           ais = Handle(AIS_Shape)::DownCast(anAISObject);
152           if (ais.IsNull()) 
153             ais = new AIS_Shape(mkEdge);
154           else {
155             ais->ResetTransformation();
156             ais->Set(mkEdge);
157             ais->SetToUpdate();
158             ais->UpdateSelection();
159           }
160       }   
161       anAISObject = ais;
162       anAISObject->SetColor(Quantity_NOC_RED);
163       break;
164     }
165   default:
166     return Standard_False;
167   }
168   
169   return Standard_True;
170 }
171