2 #include "HYDROData_ShapesGroup.h"
4 #include "HYDROData_ShapesTool.h"
6 #include <TDF_ChildIDIterator.hxx>
9 #include <TopoDS_Edge.hxx>
11 #include <TopTools_ListOfShape.hxx>
12 #include <TopTools_ListIteratorOfListOfShape.hxx>
14 #include <TNaming_Builder.hxx>
15 #include <TNaming_NamedShape.hxx>
17 #include <BRepBuilderAPI_MakeShape.hxx>
19 #include <ShapeUpgrade_UnifySameDomain.hxx>
21 IMPLEMENT_STANDARD_HANDLE(HYDROData_ShapesGroup,HYDROData_Entity)
22 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_ShapesGroup,HYDROData_Entity)
24 void HYDROData_ShapesGroup::GroupDefinition::Update( SeqOfGroupsDefs* theGroupsDefs,
25 BRepBuilderAPI_MakeShape* theAlgo )
27 if ( !theGroupsDefs || !theAlgo )
30 SeqOfGroupsDefs::Iterator anIter( *theGroupsDefs );
31 for ( ; anIter.More(); anIter.Next() )
33 GroupDefinition& aGroupDef = anIter.ChangeValue();
34 if ( aGroupDef.Shapes.IsEmpty() )
37 TopTools_ListOfShape aShapesToAdd;
38 for ( int i = 1; i <= aGroupDef.Shapes.Length(); ++i )
40 TopoDS_Shape aShape = aGroupDef.Shapes.Value( i );
42 if ( theAlgo->IsDeleted( aShape ) )
44 aGroupDef.Shapes.Remove( i );
49 const TopTools_ListOfShape& aModifiedByAlgo = theAlgo->Modified( aShape );
50 if ( !aModifiedByAlgo.IsEmpty() )
52 HYDROData_ShapesTool::AddShapes( aShapesToAdd, aModifiedByAlgo );
53 aGroupDef.Shapes.Remove( i );
58 const TopTools_ListOfShape& aGeneratedByAlgo = theAlgo->Generated( aShape );
59 if ( !aGeneratedByAlgo.IsEmpty() )
61 HYDROData_ShapesTool::AddShapes( aShapesToAdd, aGeneratedByAlgo );
62 aGroupDef.Shapes.Remove( i );
69 HYDROData_ShapesTool::AddShapes( aGroupDef.Shapes, aShapesToAdd );
73 void HYDROData_ShapesGroup::GroupDefinition::Update( SeqOfGroupsDefs* theGroupsDefs,
74 ShapeUpgrade_UnifySameDomain* theAlgo )
76 if ( !theGroupsDefs || !theAlgo )
79 SeqOfGroupsDefs::Iterator anIter( *theGroupsDefs );
80 for ( ; anIter.More(); anIter.Next() )
82 GroupDefinition& aGroupDef = anIter.ChangeValue();
83 if ( aGroupDef.Shapes.IsEmpty() )
86 TopTools_ListOfShape aShapesToAdd;
87 for ( int i = 1; i <= aGroupDef.Shapes.Length(); ++i )
89 TopoDS_Shape aShape = aGroupDef.Shapes.Value( i );
91 TopoDS_Shape aGeneratedByAlgo = theAlgo->Generated( aShape );
92 if ( aGeneratedByAlgo.IsNull() || aShape.IsEqual( aGeneratedByAlgo ) )
95 aShapesToAdd.Append( aGeneratedByAlgo );
96 aGroupDef.Shapes.Remove( i );
100 HYDROData_ShapesTool::AddShapes( aGroupDef.Shapes, aShapesToAdd );
104 HYDROData_ShapesGroup::HYDROData_ShapesGroup()
109 HYDROData_ShapesGroup::~HYDROData_ShapesGroup()
113 bool HYDROData_ShapesGroup::CanBeUpdated() const
118 bool HYDROData_ShapesGroup::CanRemove()
123 void HYDROData_ShapesGroup::AddShape( const TopoDS_Shape& theShape )
125 if ( theShape.IsNull() )
128 TDF_Label aNewLab = myLab.FindChild( DataTag_Shape ).NewChild();
130 TNaming_Builder aBuilder( aNewLab );
131 aBuilder.Generated( theShape );
134 void HYDROData_ShapesGroup::SetShapes( const TopTools_SequenceOfShape& theShapes )
138 for ( int i = 1, n = theShapes.Length(); i <= n; ++i )
140 const TopoDS_Shape& aShape = theShapes.Value( i );
145 void HYDROData_ShapesGroup::SetShapes( const TopTools_ListOfShape& theShapes )
149 TopTools_ListIteratorOfListOfShape anIter( theShapes );
150 for ( ; anIter.More(); anIter.Next() )
152 const TopoDS_Shape& aShape = anIter.Value();
157 void HYDROData_ShapesGroup::GetShapes( TopTools_SequenceOfShape& theShapes ) const
161 TDF_Label aLabel = myLab.FindChild( DataTag_Shape, false );
162 if ( aLabel.IsNull() )
165 TDF_ChildIDIterator aChildIt( aLabel, TNaming_NamedShape::GetID() );
166 for ( ; aChildIt.More(); aChildIt.Next() )
168 Handle(TNaming_NamedShape) aNamedShape =
169 Handle(TNaming_NamedShape)::DownCast( aChildIt.Value() );
170 if ( aNamedShape.IsNull() )
173 TopoDS_Shape aStoredShape = aNamedShape->Get();
174 if ( aStoredShape.IsNull() )
177 theShapes.Append( aStoredShape );
181 void HYDROData_ShapesGroup::RemoveShapes()
183 TDF_Label aLabel = myLab.FindChild( DataTag_Shape, false );
184 if ( !aLabel.IsNull() )
185 aLabel.ForgetAllAttributes();