]> SALOME platform Git repositories - modules/hydro.git/blob - src/HYDROData/HYDROData_ShapesGroup.cxx
Salome HOME
Access methods for object groups added.
[modules/hydro.git] / src / HYDROData / HYDROData_ShapesGroup.cxx
1
2 #include "HYDROData_ShapesGroup.h"
3
4 #include "HYDROData_ShapesTool.h"
5
6 #include <TDF_ChildIDIterator.hxx>
7
8 #include <TopoDS.hxx>
9 #include <TopoDS_Edge.hxx>
10
11 #include <TopTools_ListOfShape.hxx>
12 #include <TopTools_ListIteratorOfListOfShape.hxx>
13
14 #include <TNaming_Builder.hxx>
15 #include <TNaming_NamedShape.hxx>
16
17 #include <BRepBuilderAPI_MakeShape.hxx>
18
19 #include <ShapeUpgrade_UnifySameDomain.hxx>
20
21 IMPLEMENT_STANDARD_HANDLE(HYDROData_ShapesGroup,HYDROData_Entity)
22 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_ShapesGroup,HYDROData_Entity)
23
24 void HYDROData_ShapesGroup::GroupDefinition::Update( SeqOfGroupsDefs*          theGroupsDefs,
25                                                      BRepBuilderAPI_MakeShape* theAlgo )
26 {
27   if ( !theGroupsDefs || !theAlgo )
28     return;
29
30   SeqOfGroupsDefs::Iterator anIter( *theGroupsDefs );
31   for ( ; anIter.More(); anIter.Next() )
32   {
33     GroupDefinition& aGroupDef = anIter.ChangeValue();
34     if ( aGroupDef.Shapes.IsEmpty() )
35       continue;
36
37     TopTools_ListOfShape aShapesToAdd;
38     for ( int i = 1; i <= aGroupDef.Shapes.Length(); ++i )
39     {
40       TopoDS_Shape aShape = aGroupDef.Shapes.Value( i );
41
42       const TopTools_ListOfShape& aModifiedByAlgo = theAlgo->Modified( aShape );
43       if ( !aModifiedByAlgo.IsEmpty() )
44       {
45         HYDROData_ShapesTool::AddShapes( aShapesToAdd, aModifiedByAlgo );
46         aGroupDef.Shapes.Remove( i );
47         --i;
48       }
49       else
50       {
51         const TopTools_ListOfShape& aGeneratedByAlgo = theAlgo->Generated( aShape );
52         if ( !aGeneratedByAlgo.IsEmpty() )
53         {
54           HYDROData_ShapesTool::AddShapes( aShapesToAdd, aGeneratedByAlgo );
55           aGroupDef.Shapes.Remove( i );
56           --i;
57         }
58       }
59     }
60
61     HYDROData_ShapesTool::AddShapes( aGroupDef.Shapes, aShapesToAdd );
62   }
63 }
64
65 void HYDROData_ShapesGroup::GroupDefinition::Update( SeqOfGroupsDefs*              theGroupsDefs,
66                                                      ShapeUpgrade_UnifySameDomain* theAlgo )
67 {
68   if ( !theGroupsDefs || !theAlgo )
69     return;
70
71   SeqOfGroupsDefs::Iterator anIter( *theGroupsDefs );
72   for ( ; anIter.More(); anIter.Next() )
73   {
74     GroupDefinition& aGroupDef = anIter.ChangeValue();
75     if ( aGroupDef.Shapes.IsEmpty() )
76       continue;
77
78     TopTools_ListOfShape aShapesToAdd;
79     for ( int i = 1; i <= aGroupDef.Shapes.Length(); ++i )
80     {
81       TopoDS_Shape aShape = aGroupDef.Shapes.Value( i );
82
83       TopoDS_Shape aGeneratedByAlgo = theAlgo->Generated( aShape );
84       if ( aGeneratedByAlgo.IsNull() )
85       {
86         // Edge has been removed
87         aGroupDef.Shapes.Remove( i );
88         --i;
89       }
90       else if ( !aShape.IsEqual( aGeneratedByAlgo ) )
91       {
92         // Edge has been modified
93         aShapesToAdd.Append( aGeneratedByAlgo );
94         aGroupDef.Shapes.Remove( i );
95         --i;
96       }      
97     }
98
99     HYDROData_ShapesTool::AddShapes( aGroupDef.Shapes, aShapesToAdd );
100   }
101 }
102
103 void HYDROData_ShapesGroup::GroupDefinition::Dump( std::ostream& theStream ) const
104 {
105   theStream << "Name: " << Name.ToCString() << "\n";
106   HYDROData_ShapesTool::DumpSequenceOfShapes( theStream, Shapes );
107 }
108
109 void HYDROData_ShapesGroup::GroupDefinition::Dump( std::ostream&           theStream,
110                                                    const SeqOfGroupsDefs& theGroups  )
111 {
112   SeqOfGroupsDefs::Iterator anIter( theGroups );
113   for ( ; anIter.More(); anIter.Next() )
114   {
115     const GroupDefinition& aGroupDef = anIter.Value();
116     aGroupDef.Dump( theStream );
117   }
118 }
119
120
121
122 HYDROData_ShapesGroup::HYDROData_ShapesGroup()
123 : HYDROData_Entity()
124 {
125 }
126
127 HYDROData_ShapesGroup::~HYDROData_ShapesGroup()
128 {
129 }
130
131 bool HYDROData_ShapesGroup::CanBeUpdated() const
132 {
133   return false;
134 }
135
136 bool HYDROData_ShapesGroup::CanRemove()
137 {
138   return false;
139 }
140
141 void HYDROData_ShapesGroup::AddShape( const TopoDS_Shape& theShape )
142 {
143   if ( theShape.IsNull() )
144     return;
145
146   TDF_Label aNewLab = myLab.FindChild( DataTag_Shape ).NewChild();
147
148   TNaming_Builder aBuilder( aNewLab );
149   aBuilder.Generated( theShape );
150 }
151
152 void HYDROData_ShapesGroup::SetShapes( const TopTools_SequenceOfShape& theShapes )
153 {
154   RemoveShapes();
155
156   for ( int i = 1, n = theShapes.Length(); i <= n; ++i )
157   {
158     const TopoDS_Shape& aShape = theShapes.Value( i );
159     AddShape( aShape );
160   }
161 }
162
163 void HYDROData_ShapesGroup::SetShapes( const TopTools_ListOfShape& theShapes )
164 {
165   RemoveShapes();
166
167   TopTools_ListIteratorOfListOfShape anIter( theShapes );
168   for ( ; anIter.More(); anIter.Next() )
169   {
170     const TopoDS_Shape& aShape = anIter.Value();
171     AddShape( aShape );
172   }
173 }
174
175 void HYDROData_ShapesGroup::GetShapes( TopTools_SequenceOfShape& theShapes ) const
176 {
177   theShapes.Clear();
178
179   TDF_Label aLabel = myLab.FindChild( DataTag_Shape, false );
180   if ( aLabel.IsNull() )
181     return;
182
183   TDF_ChildIDIterator aChildIt( aLabel, TNaming_NamedShape::GetID() );
184   for ( ; aChildIt.More(); aChildIt.Next() )
185   {
186     Handle(TNaming_NamedShape) aNamedShape = 
187       Handle(TNaming_NamedShape)::DownCast( aChildIt.Value() );
188     if ( aNamedShape.IsNull() )
189       continue;
190
191     TopoDS_Shape aStoredShape = aNamedShape->Get();
192     if ( aStoredShape.IsNull() )
193       continue;
194
195     theShapes.Append( aStoredShape );
196   }
197 }
198
199 void HYDROData_ShapesGroup::RemoveShapes()
200 {
201   TDF_Label aLabel = myLab.FindChild( DataTag_Shape, false );
202   if ( !aLabel.IsNull() )
203     aLabel.ForgetAllAttributes();
204 }
205