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