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>
33 #include <BRepTools_ReShape.hxx>
35 IMPLEMENT_STANDARD_HANDLE(HYDROData_ShapesGroup,HYDROData_Entity)
36 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_ShapesGroup,HYDROData_Entity)
38 void HYDROData_ShapesGroup::GroupDefinition::Update( SeqOfGroupsDefs* theGroupsDefs,
39 BRepBuilderAPI_MakeShape* theAlgo )
41 if ( !theGroupsDefs || !theAlgo )
44 SeqOfGroupsDefs::Iterator anIter( *theGroupsDefs );
45 for ( ; anIter.More(); anIter.Next() )
47 GroupDefinition& aGroupDef = anIter.ChangeValue();
48 if ( aGroupDef.Shapes.IsEmpty() )
51 TopTools_ListOfShape aShapesToAdd;
52 for ( int i = 1; i <= aGroupDef.Shapes.Length(); ++i )
54 TopoDS_Shape aShape = aGroupDef.Shapes.Value( i );
56 const TopTools_ListOfShape& aModifiedByAlgo = theAlgo->Modified( aShape );
57 if ( !aModifiedByAlgo.IsEmpty() )
59 HYDROData_ShapesTool::AddShapes( aShapesToAdd, aModifiedByAlgo );
60 aGroupDef.Shapes.Remove( i );
65 const TopTools_ListOfShape& aGeneratedByAlgo = theAlgo->Generated( aShape );
66 if ( !aGeneratedByAlgo.IsEmpty() )
68 HYDROData_ShapesTool::AddShapes( aShapesToAdd, aGeneratedByAlgo );
69 aGroupDef.Shapes.Remove( i );
75 HYDROData_ShapesTool::AddShapes( aGroupDef.Shapes, aShapesToAdd );
79 void HYDROData_ShapesGroup::GroupDefinition::Update( SeqOfGroupsDefs* theGroupsDefs,
80 ShapeUpgrade_UnifySameDomain* theAlgo )
82 if ( !theGroupsDefs || !theAlgo )
85 SeqOfGroupsDefs::Iterator anIter( *theGroupsDefs );
86 for ( ; anIter.More(); anIter.Next() )
88 GroupDefinition& aGroupDef = anIter.ChangeValue();
89 if ( aGroupDef.Shapes.IsEmpty() )
92 TopTools_ListOfShape aShapesToAdd;
93 for ( int i = 1; i <= aGroupDef.Shapes.Length(); ++i )
95 TopoDS_Shape aShape = aGroupDef.Shapes.Value( i );
97 TopoDS_Shape aGeneratedByAlgo = theAlgo->Generated( aShape );
98 if ( aGeneratedByAlgo.IsNull() )
100 // Edge has been removed
101 aGroupDef.Shapes.Remove( i );
104 else if ( !aShape.IsEqual( aGeneratedByAlgo ) )
106 // Edge has been modified
107 aShapesToAdd.Append( aGeneratedByAlgo );
108 aGroupDef.Shapes.Remove( i );
113 HYDROData_ShapesTool::AddShapes( aGroupDef.Shapes, aShapesToAdd );
117 void HYDROData_ShapesGroup::GroupDefinition::Update( SeqOfGroupsDefs* theGroupsDefs,
118 BRepTools_ReShape* theAlgo )
120 if ( !theGroupsDefs || !theAlgo )
123 SeqOfGroupsDefs::Iterator anIter( *theGroupsDefs );
124 for ( ; anIter.More(); anIter.Next() )
126 GroupDefinition& aGroupDef = anIter.ChangeValue();
127 if ( aGroupDef.Shapes.IsEmpty() )
130 TopTools_ListOfShape aShapesToAdd;
131 for ( int i = 1; i <= aGroupDef.Shapes.Length(); ++i )
133 TopoDS_Shape aShape = aGroupDef.Shapes.Value( i );
135 TopoDS_Shape aGeneratedByAlgo = theAlgo->Value( aShape );
136 if ( aGeneratedByAlgo.IsNull() )
138 // Edge has been removed
139 aGroupDef.Shapes.Remove( i );
142 else if ( !aShape.IsEqual( aGeneratedByAlgo ) )
144 // Edge has been modified
145 aShapesToAdd.Append( aGeneratedByAlgo );
146 aGroupDef.Shapes.Remove( i );
151 HYDROData_ShapesTool::AddShapes( aGroupDef.Shapes, aShapesToAdd );
155 void HYDROData_ShapesGroup::GroupDefinition::Dump( std::ostream& theStream ) const
157 theStream << "Name: " << Name.ToCString() << "\n";
158 HYDROData_ShapesTool::DumpSequenceOfShapes( theStream, Shapes );
161 void HYDROData_ShapesGroup::GroupDefinition::Dump( std::ostream& theStream,
162 const SeqOfGroupsDefs& theGroups )
164 SeqOfGroupsDefs::Iterator anIter( theGroups );
165 for ( ; anIter.More(); anIter.Next() )
167 const GroupDefinition& aGroupDef = anIter.Value();
168 aGroupDef.Dump( theStream );
174 HYDROData_ShapesGroup::HYDROData_ShapesGroup()
175 : HYDROData_Entity( Geom_Groups )
179 HYDROData_ShapesGroup::~HYDROData_ShapesGroup()
183 bool HYDROData_ShapesGroup::CanBeUpdated() const
188 bool HYDROData_ShapesGroup::CanRemove()
193 void HYDROData_ShapesGroup::AddShape( const TopoDS_Shape& theShape )
195 if ( theShape.IsNull() )
198 TDF_Label aNewLab = myLab.FindChild( DataTag_Shape ).NewChild();
200 TNaming_Builder aBuilder( aNewLab );
201 aBuilder.Generated( theShape );
204 void HYDROData_ShapesGroup::SetShapes( const TopTools_SequenceOfShape& theShapes )
208 for ( int i = 1, n = theShapes.Length(); i <= n; ++i )
210 const TopoDS_Shape& aShape = theShapes.Value( i );
215 void HYDROData_ShapesGroup::SetShapes( const TopTools_ListOfShape& theShapes )
219 TopTools_ListIteratorOfListOfShape anIter( theShapes );
220 for ( ; anIter.More(); anIter.Next() )
222 const TopoDS_Shape& aShape = anIter.Value();
227 void HYDROData_ShapesGroup::GetShapes( TopTools_SequenceOfShape& theShapes ) const
231 TDF_Label aLabel = myLab.FindChild( DataTag_Shape, false );
232 if ( aLabel.IsNull() )
235 TDF_ChildIDIterator aChildIt( aLabel, TNaming_NamedShape::GetID() );
236 for ( ; aChildIt.More(); aChildIt.Next() )
238 Handle(TNaming_NamedShape) aNamedShape =
239 Handle(TNaming_NamedShape)::DownCast( aChildIt.Value() );
240 if ( aNamedShape.IsNull() )
243 TopoDS_Shape aStoredShape = aNamedShape->Get();
244 if ( aStoredShape.IsNull() )
247 theShapes.Append( aStoredShape );
251 void HYDROData_ShapesGroup::RemoveShapes()
253 TDF_Label aLabel = myLab.FindChild( DataTag_Shape, false );
254 if ( !aLabel.IsNull() )
255 aLabel.ForgetAllAttributes();