1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "HYDROData_ShapesGroup.h"
20 #include "HYDROData_ShapesTool.h"
22 #include <BRepBuilderAPI_MakeShape.hxx>
23 #include <TDF_ChildIDIterator.hxx>
24 #include <TNaming_Builder.hxx>
25 #include <TNaming_NamedShape.hxx>
28 #include <TopoDS_Edge.hxx>
30 #include <TopTools_ListOfShape.hxx>
31 #include <TopTools_ListIteratorOfListOfShape.hxx>
32 #include <ShapeUpgrade_UnifySameDomain.hxx>
34 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_ShapesGroup,HYDROData_Entity)
36 void HYDROData_ShapesGroup::GroupDefinition::Update( SeqOfGroupsDefs* theGroupsDefs,
37 BRepBuilderAPI_MakeShape* theAlgo )
39 if ( !theGroupsDefs || !theAlgo )
42 SeqOfGroupsDefs::Iterator anIter( *theGroupsDefs );
43 for ( ; anIter.More(); anIter.Next() )
45 GroupDefinition& aGroupDef = anIter.ChangeValue();
46 if ( aGroupDef.Shapes.IsEmpty() )
49 TopTools_ListOfShape aShapesToAdd;
50 for ( int i = 1; i <= aGroupDef.Shapes.Length(); ++i )
52 TopoDS_Shape aShape = aGroupDef.Shapes.Value( i );
54 const TopTools_ListOfShape& aModifiedByAlgo = theAlgo->Modified( aShape );
55 if ( !aModifiedByAlgo.IsEmpty() )
57 HYDROData_ShapesTool::AddShapes( aShapesToAdd, aModifiedByAlgo );
58 aGroupDef.Shapes.Remove( i );
63 const TopTools_ListOfShape& aGeneratedByAlgo = theAlgo->Generated( aShape );
64 if ( !aGeneratedByAlgo.IsEmpty() )
66 HYDROData_ShapesTool::AddShapes( aShapesToAdd, aGeneratedByAlgo );
67 aGroupDef.Shapes.Remove( i );
73 HYDROData_ShapesTool::AddShapes( aGroupDef.Shapes, aShapesToAdd );
77 void HYDROData_ShapesGroup::GroupDefinition::Update( SeqOfGroupsDefs* theGroupsDefs,
78 ShapeUpgrade_UnifySameDomain* theAlgo )
80 if ( !theGroupsDefs || !theAlgo )
83 SeqOfGroupsDefs::Iterator anIter( *theGroupsDefs );
84 for ( ; anIter.More(); anIter.Next() )
86 GroupDefinition& aGroupDef = anIter.ChangeValue();
87 if ( aGroupDef.Shapes.IsEmpty() )
90 TopTools_ListOfShape aShapesToAdd;
91 for ( int i = 1; i <= aGroupDef.Shapes.Length(); ++i )
93 TopoDS_Shape aShape = aGroupDef.Shapes.Value( i );
95 TopoDS_Shape aGeneratedByAlgo = theAlgo->Generated( aShape );
96 if ( aGeneratedByAlgo.IsNull() )
98 // Edge has been removed
99 aGroupDef.Shapes.Remove( i );
102 else if ( !aShape.IsEqual( aGeneratedByAlgo ) )
104 // Edge has been modified
105 aShapesToAdd.Append( aGeneratedByAlgo );
106 aGroupDef.Shapes.Remove( i );
111 HYDROData_ShapesTool::AddShapes( aGroupDef.Shapes, aShapesToAdd );
115 void HYDROData_ShapesGroup::GroupDefinition::Dump( std::ostream& theStream ) const
117 theStream << "Name: " << Name.ToCString() << "\n";
118 HYDROData_ShapesTool::DumpSequenceOfShapes( theStream, Shapes );
121 void HYDROData_ShapesGroup::GroupDefinition::Dump( std::ostream& theStream,
122 const SeqOfGroupsDefs& theGroups )
124 SeqOfGroupsDefs::Iterator anIter( theGroups );
125 for ( ; anIter.More(); anIter.Next() )
127 const GroupDefinition& aGroupDef = anIter.Value();
128 aGroupDef.Dump( theStream );
134 HYDROData_ShapesGroup::HYDROData_ShapesGroup()
135 : HYDROData_Entity( Geom_Groups )
139 HYDROData_ShapesGroup::~HYDROData_ShapesGroup()
143 bool HYDROData_ShapesGroup::CanBeUpdated() const
148 bool HYDROData_ShapesGroup::CanRemove()
153 void HYDROData_ShapesGroup::AddShape( const TopoDS_Shape& theShape )
155 if ( theShape.IsNull() )
158 TDF_Label aNewLab = myLab.FindChild( DataTag_Shape ).NewChild();
160 TNaming_Builder aBuilder( aNewLab );
161 aBuilder.Generated( theShape );
164 void HYDROData_ShapesGroup::SetShapes( const TopTools_SequenceOfShape& theShapes )
168 for ( int i = 1, n = theShapes.Length(); i <= n; ++i )
170 const TopoDS_Shape& aShape = theShapes.Value( i );
175 void HYDROData_ShapesGroup::SetShapes( const TopTools_ListOfShape& theShapes )
179 TopTools_ListIteratorOfListOfShape anIter( theShapes );
180 for ( ; anIter.More(); anIter.Next() )
182 const TopoDS_Shape& aShape = anIter.Value();
187 void HYDROData_ShapesGroup::GetShapes( TopTools_SequenceOfShape& theShapes ) const
191 TDF_Label aLabel = myLab.FindChild( DataTag_Shape, false );
192 if ( aLabel.IsNull() )
195 TDF_ChildIDIterator aChildIt( aLabel, TNaming_NamedShape::GetID() );
196 for ( ; aChildIt.More(); aChildIt.Next() )
198 Handle(TNaming_NamedShape) aNamedShape =
199 Handle(TNaming_NamedShape)::DownCast( aChildIt.Value() );
200 if ( aNamedShape.IsNull() )
203 TopoDS_Shape aStoredShape = aNamedShape->Get();
204 if ( aStoredShape.IsNull() )
207 theShapes.Append( aStoredShape );
211 void HYDROData_ShapesGroup::RemoveShapes()
213 TDF_Label aLabel = myLab.FindChild( DataTag_Shape, false );
214 if ( !aLabel.IsNull() )
215 aLabel.ForgetAllAttributes();