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 const TopTools_ListOfShape& aModifiedByAlgo = theAlgo->Modified( aShape );
43 if ( !aModifiedByAlgo.IsEmpty() )
45 HYDROData_ShapesTool::AddShapes( aShapesToAdd, aModifiedByAlgo );
46 aGroupDef.Shapes.Remove( i );
51 const TopTools_ListOfShape& aGeneratedByAlgo = theAlgo->Generated( aShape );
52 if ( !aGeneratedByAlgo.IsEmpty() )
54 HYDROData_ShapesTool::AddShapes( aShapesToAdd, aGeneratedByAlgo );
55 aGroupDef.Shapes.Remove( i );
61 HYDROData_ShapesTool::AddShapes( aGroupDef.Shapes, aShapesToAdd );
65 void HYDROData_ShapesGroup::GroupDefinition::Update( SeqOfGroupsDefs* theGroupsDefs,
66 ShapeUpgrade_UnifySameDomain* theAlgo )
68 if ( !theGroupsDefs || !theAlgo )
71 SeqOfGroupsDefs::Iterator anIter( *theGroupsDefs );
72 for ( ; anIter.More(); anIter.Next() )
74 GroupDefinition& aGroupDef = anIter.ChangeValue();
75 if ( aGroupDef.Shapes.IsEmpty() )
78 TopTools_ListOfShape aShapesToAdd;
79 for ( int i = 1; i <= aGroupDef.Shapes.Length(); ++i )
81 TopoDS_Shape aShape = aGroupDef.Shapes.Value( i );
83 TopoDS_Shape aGeneratedByAlgo = theAlgo->Generated( aShape );
84 if ( aGeneratedByAlgo.IsNull() )
86 // Edge has been removed
87 aGroupDef.Shapes.Remove( i );
90 else if ( !aShape.IsEqual( aGeneratedByAlgo ) )
92 // Edge has been modified
93 aShapesToAdd.Append( aGeneratedByAlgo );
94 aGroupDef.Shapes.Remove( i );
99 HYDROData_ShapesTool::AddShapes( aGroupDef.Shapes, aShapesToAdd );
103 void HYDROData_ShapesGroup::GroupDefinition::Dump( std::ostream& theStream ) const
105 theStream << "Name: " << Name.ToCString() << "\n";
106 HYDROData_ShapesTool::DumpSequenceOfShapes( theStream, Shapes );
109 void HYDROData_ShapesGroup::GroupDefinition::Dump( std::ostream& theStream,
110 const SeqOfGroupsDefs& theGroups )
112 SeqOfGroupsDefs::Iterator anIter( theGroups );
113 for ( ; anIter.More(); anIter.Next() )
115 const GroupDefinition& aGroupDef = anIter.Value();
116 aGroupDef.Dump( theStream );
122 HYDROData_ShapesGroup::HYDROData_ShapesGroup()
127 HYDROData_ShapesGroup::~HYDROData_ShapesGroup()
131 bool HYDROData_ShapesGroup::CanBeUpdated() const
136 bool HYDROData_ShapesGroup::CanRemove()
141 void HYDROData_ShapesGroup::AddShape( const TopoDS_Shape& theShape )
143 if ( theShape.IsNull() )
146 TDF_Label aNewLab = myLab.FindChild( DataTag_Shape ).NewChild();
148 TNaming_Builder aBuilder( aNewLab );
149 aBuilder.Generated( theShape );
152 void HYDROData_ShapesGroup::SetShapes( const TopTools_SequenceOfShape& theShapes )
156 for ( int i = 1, n = theShapes.Length(); i <= n; ++i )
158 const TopoDS_Shape& aShape = theShapes.Value( i );
163 void HYDROData_ShapesGroup::SetShapes( const TopTools_ListOfShape& theShapes )
167 TopTools_ListIteratorOfListOfShape anIter( theShapes );
168 for ( ; anIter.More(); anIter.Next() )
170 const TopoDS_Shape& aShape = anIter.Value();
175 void HYDROData_ShapesGroup::GetShapes( TopTools_SequenceOfShape& theShapes ) const
179 TDF_Label aLabel = myLab.FindChild( DataTag_Shape, false );
180 if ( aLabel.IsNull() )
183 TDF_ChildIDIterator aChildIt( aLabel, TNaming_NamedShape::GetID() );
184 for ( ; aChildIt.More(); aChildIt.Next() )
186 Handle(TNaming_NamedShape) aNamedShape =
187 Handle(TNaming_NamedShape)::DownCast( aChildIt.Value() );
188 if ( aNamedShape.IsNull() )
191 TopoDS_Shape aStoredShape = aNamedShape->Get();
192 if ( aStoredShape.IsNull() )
195 theShapes.Append( aStoredShape );
199 void HYDROData_ShapesGroup::RemoveShapes()
201 TDF_Label aLabel = myLab.FindChild( DataTag_Shape, false );
202 if ( !aLabel.IsNull() )
203 aLabel.ForgetAllAttributes();