1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "HYDROData_ShapesGroup.h"
25 #include "HYDROData_ShapesTool.h"
27 #include <TDF_ChildIDIterator.hxx>
30 #include <TopoDS_Edge.hxx>
32 #include <TopTools_ListOfShape.hxx>
33 #include <TopTools_ListIteratorOfListOfShape.hxx>
35 #include <TNaming_Builder.hxx>
36 #include <TNaming_NamedShape.hxx>
38 #include <BRepBuilderAPI_MakeShape.hxx>
40 #include <ShapeUpgrade_UnifySameDomain.hxx>
42 IMPLEMENT_STANDARD_HANDLE(HYDROData_ShapesGroup,HYDROData_Entity)
43 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_ShapesGroup,HYDROData_Entity)
45 void HYDROData_ShapesGroup::GroupDefinition::Update( SeqOfGroupsDefs* theGroupsDefs,
46 BRepBuilderAPI_MakeShape* theAlgo )
48 if ( !theGroupsDefs || !theAlgo )
51 SeqOfGroupsDefs::Iterator anIter( *theGroupsDefs );
52 for ( ; anIter.More(); anIter.Next() )
54 GroupDefinition& aGroupDef = anIter.ChangeValue();
55 if ( aGroupDef.Shapes.IsEmpty() )
58 TopTools_ListOfShape aShapesToAdd;
59 for ( int i = 1; i <= aGroupDef.Shapes.Length(); ++i )
61 TopoDS_Shape aShape = aGroupDef.Shapes.Value( i );
63 const TopTools_ListOfShape& aModifiedByAlgo = theAlgo->Modified( aShape );
64 if ( !aModifiedByAlgo.IsEmpty() )
66 HYDROData_ShapesTool::AddShapes( aShapesToAdd, aModifiedByAlgo );
67 aGroupDef.Shapes.Remove( i );
72 const TopTools_ListOfShape& aGeneratedByAlgo = theAlgo->Generated( aShape );
73 if ( !aGeneratedByAlgo.IsEmpty() )
75 HYDROData_ShapesTool::AddShapes( aShapesToAdd, aGeneratedByAlgo );
76 aGroupDef.Shapes.Remove( i );
82 HYDROData_ShapesTool::AddShapes( aGroupDef.Shapes, aShapesToAdd );
86 void HYDROData_ShapesGroup::GroupDefinition::Update( SeqOfGroupsDefs* theGroupsDefs,
87 ShapeUpgrade_UnifySameDomain* theAlgo )
89 if ( !theGroupsDefs || !theAlgo )
92 SeqOfGroupsDefs::Iterator anIter( *theGroupsDefs );
93 for ( ; anIter.More(); anIter.Next() )
95 GroupDefinition& aGroupDef = anIter.ChangeValue();
96 if ( aGroupDef.Shapes.IsEmpty() )
99 TopTools_ListOfShape aShapesToAdd;
100 for ( int i = 1; i <= aGroupDef.Shapes.Length(); ++i )
102 TopoDS_Shape aShape = aGroupDef.Shapes.Value( i );
104 TopoDS_Shape aGeneratedByAlgo = theAlgo->Generated( aShape );
105 if ( aGeneratedByAlgo.IsNull() )
107 // Edge has been removed
108 aGroupDef.Shapes.Remove( i );
111 else if ( !aShape.IsEqual( aGeneratedByAlgo ) )
113 // Edge has been modified
114 aShapesToAdd.Append( aGeneratedByAlgo );
115 aGroupDef.Shapes.Remove( i );
120 HYDROData_ShapesTool::AddShapes( aGroupDef.Shapes, aShapesToAdd );
124 void HYDROData_ShapesGroup::GroupDefinition::Dump( std::ostream& theStream ) const
126 theStream << "Name: " << Name.ToCString() << "\n";
127 HYDROData_ShapesTool::DumpSequenceOfShapes( theStream, Shapes );
130 void HYDROData_ShapesGroup::GroupDefinition::Dump( std::ostream& theStream,
131 const SeqOfGroupsDefs& theGroups )
133 SeqOfGroupsDefs::Iterator anIter( theGroups );
134 for ( ; anIter.More(); anIter.Next() )
136 const GroupDefinition& aGroupDef = anIter.Value();
137 aGroupDef.Dump( theStream );
143 HYDROData_ShapesGroup::HYDROData_ShapesGroup()
148 HYDROData_ShapesGroup::~HYDROData_ShapesGroup()
152 bool HYDROData_ShapesGroup::CanBeUpdated() const
157 bool HYDROData_ShapesGroup::CanRemove()
162 void HYDROData_ShapesGroup::AddShape( const TopoDS_Shape& theShape )
164 if ( theShape.IsNull() )
167 TDF_Label aNewLab = myLab.FindChild( DataTag_Shape ).NewChild();
169 TNaming_Builder aBuilder( aNewLab );
170 aBuilder.Generated( theShape );
173 void HYDROData_ShapesGroup::SetShapes( const TopTools_SequenceOfShape& theShapes )
177 for ( int i = 1, n = theShapes.Length(); i <= n; ++i )
179 const TopoDS_Shape& aShape = theShapes.Value( i );
184 void HYDROData_ShapesGroup::SetShapes( const TopTools_ListOfShape& theShapes )
188 TopTools_ListIteratorOfListOfShape anIter( theShapes );
189 for ( ; anIter.More(); anIter.Next() )
191 const TopoDS_Shape& aShape = anIter.Value();
196 void HYDROData_ShapesGroup::GetShapes( TopTools_SequenceOfShape& theShapes ) const
200 TDF_Label aLabel = myLab.FindChild( DataTag_Shape, false );
201 if ( aLabel.IsNull() )
204 TDF_ChildIDIterator aChildIt( aLabel, TNaming_NamedShape::GetID() );
205 for ( ; aChildIt.More(); aChildIt.Next() )
207 Handle(TNaming_NamedShape) aNamedShape =
208 Handle(TNaming_NamedShape)::DownCast( aChildIt.Value() );
209 if ( aNamedShape.IsNull() )
212 TopoDS_Shape aStoredShape = aNamedShape->Get();
213 if ( aStoredShape.IsNull() )
216 theShapes.Append( aStoredShape );
220 void HYDROData_ShapesGroup::RemoveShapes()
222 TDF_Label aLabel = myLab.FindChild( DataTag_Shape, false );
223 if ( !aLabel.IsNull() )
224 aLabel.ForgetAllAttributes();