Salome HOME
Minor change.
[modules/hydro.git] / src / HYDROData / HYDROData_ShapesGroup.cxx
1
2 #include "HYDROData_ShapesGroup.h"
3
4 #include <TDF_ChildIDIterator.hxx>
5
6 #include <TopoDS.hxx>
7 #include <TopoDS_Edge.hxx>
8
9 #include <TNaming_Builder.hxx>
10 #include <TNaming_NamedShape.hxx>
11
12 IMPLEMENT_STANDARD_HANDLE(HYDROData_ShapesGroup,HYDROData_Entity)
13 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_ShapesGroup,HYDROData_Entity)
14
15 HYDROData_ShapesGroup::HYDROData_ShapesGroup()
16 : HYDROData_Entity()
17 {
18 }
19
20 HYDROData_ShapesGroup::~HYDROData_ShapesGroup()
21 {
22 }
23
24 bool HYDROData_ShapesGroup::CanBeUpdated() const
25 {
26   return false;
27 }
28
29 bool HYDROData_ShapesGroup::CanRemove()
30 {
31   return false;
32 }
33
34 void HYDROData_ShapesGroup::AddShape( const TopoDS_Shape& theShape )
35 {
36   if ( theShape.IsNull() )
37     return;
38
39   TDF_Label aNewLab = myLab.FindChild( DataTag_Shape ).NewChild();
40
41   TNaming_Builder aBuilder( aNewLab );
42   aBuilder.Generated( theShape );
43 }
44
45 void HYDROData_ShapesGroup::SetShapes( const TopTools_SequenceOfShape& theShapes )
46 {
47   RemoveShapes();
48
49   for ( int i = 1, n = theShapes.Length(); i <= n; ++i )
50   {
51     const TopoDS_Shape& aShape = theShapes.Value( i );
52     AddShape( aShape );
53   }
54 }
55
56 void HYDROData_ShapesGroup::GetShapes( TopTools_SequenceOfShape& theShapes ) const
57 {
58   theShapes.Clear();
59
60   TDF_Label aLabel = myLab.FindChild( DataTag_Shape, false );
61   if ( aLabel.IsNull() )
62     return;
63
64   TDF_ChildIDIterator aChildIt( aLabel, TNaming_NamedShape::GetID() );
65   for ( ; aChildIt.More(); aChildIt.Next() )
66   {
67     Handle(TNaming_NamedShape) aNamedShape = 
68       Handle(TNaming_NamedShape)::DownCast( aChildIt.Value() );
69     if ( aNamedShape.IsNull() )
70       continue;
71
72     TopoDS_Shape aStoredShape = aNamedShape->Get();
73     if ( aStoredShape.IsNull() )
74       continue;
75
76     theShapes.Append( aStoredShape );
77   }
78 }
79
80 void HYDROData_ShapesGroup::RemoveShapes()
81 {
82   TDF_Label aLabel = myLab.FindChild( DataTag_Shape, false );
83   if ( !aLabel.IsNull() )
84     aLabel.ForgetAllAttributes();
85 }
86