Salome HOME
Adding of list of shapes method added.
[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 <TopTools_ListOfShape.hxx>
10 #include <TopTools_ListIteratorOfListOfShape.hxx>
11
12 #include <TNaming_Builder.hxx>
13 #include <TNaming_NamedShape.hxx>
14
15 IMPLEMENT_STANDARD_HANDLE(HYDROData_ShapesGroup,HYDROData_Entity)
16 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_ShapesGroup,HYDROData_Entity)
17
18 HYDROData_ShapesGroup::HYDROData_ShapesGroup()
19 : HYDROData_Entity()
20 {
21 }
22
23 HYDROData_ShapesGroup::~HYDROData_ShapesGroup()
24 {
25 }
26
27 bool HYDROData_ShapesGroup::CanBeUpdated() const
28 {
29   return false;
30 }
31
32 bool HYDROData_ShapesGroup::CanRemove()
33 {
34   return false;
35 }
36
37 void HYDROData_ShapesGroup::AddShape( const TopoDS_Shape& theShape )
38 {
39   if ( theShape.IsNull() )
40     return;
41
42   TDF_Label aNewLab = myLab.FindChild( DataTag_Shape ).NewChild();
43
44   TNaming_Builder aBuilder( aNewLab );
45   aBuilder.Generated( theShape );
46 }
47
48 void HYDROData_ShapesGroup::SetShapes( const TopTools_SequenceOfShape& theShapes )
49 {
50   RemoveShapes();
51
52   for ( int i = 1, n = theShapes.Length(); i <= n; ++i )
53   {
54     const TopoDS_Shape& aShape = theShapes.Value( i );
55     AddShape( aShape );
56   }
57 }
58
59 void HYDROData_ShapesGroup::SetShapes( const TopTools_ListOfShape& theShapes )
60 {
61   RemoveShapes();
62
63   TopTools_ListIteratorOfListOfShape anIter( theShapes );
64   for ( ; anIter.More(); anIter.Next() )
65   {
66     const TopoDS_Shape& aShape = anIter.Value();
67     AddShape( aShape );
68   }
69 }
70
71 void HYDROData_ShapesGroup::GetShapes( TopTools_SequenceOfShape& theShapes ) const
72 {
73   theShapes.Clear();
74
75   TDF_Label aLabel = myLab.FindChild( DataTag_Shape, false );
76   if ( aLabel.IsNull() )
77     return;
78
79   TDF_ChildIDIterator aChildIt( aLabel, TNaming_NamedShape::GetID() );
80   for ( ; aChildIt.More(); aChildIt.Next() )
81   {
82     Handle(TNaming_NamedShape) aNamedShape = 
83       Handle(TNaming_NamedShape)::DownCast( aChildIt.Value() );
84     if ( aNamedShape.IsNull() )
85       continue;
86
87     TopoDS_Shape aStoredShape = aNamedShape->Get();
88     if ( aStoredShape.IsNull() )
89       continue;
90
91     theShapes.Append( aStoredShape );
92   }
93 }
94
95 void HYDROData_ShapesGroup::RemoveShapes()
96 {
97   TDF_Label aLabel = myLab.FindChild( DataTag_Shape, false );
98   if ( !aLabel.IsNull() )
99     aLabel.ForgetAllAttributes();
100 }
101