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_HANDLE(HYDROData_ShapesGroup,HYDROData_Entity)
35 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_ShapesGroup,HYDROData_Entity)
37 void HYDROData_ShapesGroup::GroupDefinition::Update( SeqOfGroupsDefs* theGroupsDefs,
38 BRepBuilderAPI_MakeShape* theAlgo )
40 if ( !theGroupsDefs || !theAlgo )
43 SeqOfGroupsDefs::Iterator anIter( *theGroupsDefs );
44 for ( ; anIter.More(); anIter.Next() )
46 GroupDefinition& aGroupDef = anIter.ChangeValue();
47 if ( aGroupDef.Shapes.IsEmpty() )
50 TopTools_ListOfShape aShapesToAdd;
51 for ( int i = 1; i <= aGroupDef.Shapes.Length(); ++i )
53 TopoDS_Shape aShape = aGroupDef.Shapes.Value( i );
55 const TopTools_ListOfShape& aModifiedByAlgo = theAlgo->Modified( aShape );
56 if ( !aModifiedByAlgo.IsEmpty() )
58 HYDROData_ShapesTool::AddShapes( aShapesToAdd, aModifiedByAlgo );
59 aGroupDef.Shapes.Remove( i );
64 const TopTools_ListOfShape& aGeneratedByAlgo = theAlgo->Generated( aShape );
65 if ( !aGeneratedByAlgo.IsEmpty() )
67 HYDROData_ShapesTool::AddShapes( aShapesToAdd, aGeneratedByAlgo );
68 aGroupDef.Shapes.Remove( i );
74 HYDROData_ShapesTool::AddShapes( aGroupDef.Shapes, aShapesToAdd );
78 void HYDROData_ShapesGroup::GroupDefinition::Update( SeqOfGroupsDefs* theGroupsDefs,
79 ShapeUpgrade_UnifySameDomain* theAlgo )
81 if ( !theGroupsDefs || !theAlgo )
84 SeqOfGroupsDefs::Iterator anIter( *theGroupsDefs );
85 for ( ; anIter.More(); anIter.Next() )
87 GroupDefinition& aGroupDef = anIter.ChangeValue();
88 if ( aGroupDef.Shapes.IsEmpty() )
91 TopTools_ListOfShape aShapesToAdd;
92 for ( int i = 1; i <= aGroupDef.Shapes.Length(); ++i )
94 TopoDS_Shape aShape = aGroupDef.Shapes.Value( i );
96 TopoDS_Shape aGeneratedByAlgo = theAlgo->Generated( aShape );
97 if ( aGeneratedByAlgo.IsNull() )
99 // Edge has been removed
100 aGroupDef.Shapes.Remove( i );
103 else if ( !aShape.IsEqual( aGeneratedByAlgo ) )
105 // Edge has been modified
106 aShapesToAdd.Append( aGeneratedByAlgo );
107 aGroupDef.Shapes.Remove( i );
112 HYDROData_ShapesTool::AddShapes( aGroupDef.Shapes, aShapesToAdd );
116 void HYDROData_ShapesGroup::GroupDefinition::Dump( std::ostream& theStream ) const
118 theStream << "Name: " << Name.ToCString() << "\n";
119 HYDROData_ShapesTool::DumpSequenceOfShapes( theStream, Shapes );
122 void HYDROData_ShapesGroup::GroupDefinition::Dump( std::ostream& theStream,
123 const SeqOfGroupsDefs& theGroups )
125 SeqOfGroupsDefs::Iterator anIter( theGroups );
126 for ( ; anIter.More(); anIter.Next() )
128 const GroupDefinition& aGroupDef = anIter.Value();
129 aGroupDef.Dump( theStream );
135 HYDROData_ShapesGroup::HYDROData_ShapesGroup()
136 : HYDROData_Entity( Geom_Groups )
140 HYDROData_ShapesGroup::~HYDROData_ShapesGroup()
144 bool HYDROData_ShapesGroup::CanBeUpdated() const
149 bool HYDROData_ShapesGroup::CanRemove()
154 void HYDROData_ShapesGroup::AddShape( const TopoDS_Shape& theShape )
156 if ( theShape.IsNull() )
159 TDF_Label aNewLab = myLab.FindChild( DataTag_Shape ).NewChild();
161 TNaming_Builder aBuilder( aNewLab );
162 aBuilder.Generated( theShape );
165 void HYDROData_ShapesGroup::SetShapes( const TopTools_SequenceOfShape& theShapes )
169 for ( int i = 1, n = theShapes.Length(); i <= n; ++i )
171 const TopoDS_Shape& aShape = theShapes.Value( i );
176 void HYDROData_ShapesGroup::SetShapes( const TopTools_ListOfShape& theShapes )
180 TopTools_ListIteratorOfListOfShape anIter( theShapes );
181 for ( ; anIter.More(); anIter.Next() )
183 const TopoDS_Shape& aShape = anIter.Value();
188 void HYDROData_ShapesGroup::GetShapes( TopTools_SequenceOfShape& theShapes ) const
192 TDF_Label aLabel = myLab.FindChild( DataTag_Shape, false );
193 if ( aLabel.IsNull() )
196 TDF_ChildIDIterator aChildIt( aLabel, TNaming_NamedShape::GetID() );
197 for ( ; aChildIt.More(); aChildIt.Next() )
199 Handle(TNaming_NamedShape) aNamedShape =
200 Handle(TNaming_NamedShape)::DownCast( aChildIt.Value() );
201 if ( aNamedShape.IsNull() )
204 TopoDS_Shape aStoredShape = aNamedShape->Get();
205 if ( aStoredShape.IsNull() )
208 theShapes.Append( aStoredShape );
212 void HYDROData_ShapesGroup::RemoveShapes()
214 TDF_Label aLabel = myLab.FindChild( DataTag_Shape, false );
215 if ( !aLabel.IsNull() )
216 aLabel.ForgetAllAttributes();