1 // Copyright (C) 2007-2013 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.
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 "HYDROGUI_SplitZonesTool.h"
25 #include <HYDROData_Zone.h>
27 HYDROGUI_SplitZonesTool::SplitDataList
28 HYDROGUI_SplitZonesTool::SplitZones( const HYDROData_SequenceOfObjects& theZoneList,
29 const Handle(HYDROData_Polyline)& thePolylie )
31 SplitDataList anOutputSplitDataList;
33 SplitDataList anInputSplitDataList;
34 for( int anIndex = 1, aLength = theZoneList.Length(); anIndex <= aLength; anIndex++ )
36 Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( theZoneList.Value( anIndex ) );
39 SplitData aSplitData( aZone->GetPainterPath(), aZone->GetName() );
40 anInputSplitDataList.append( aSplitData );
44 SplitDataListIterator anInputIter( anInputSplitDataList );
45 while( anInputIter.hasNext() )
47 const SplitData& anInputSplitData = anInputIter.next();
48 if( anOutputSplitDataList.isEmpty() )
49 anOutputSplitDataList.append( anInputSplitData );
52 SplitDataList aSplitDataList;
53 SplitDataListIterator anOutputIter( anOutputSplitDataList );
54 while( anOutputIter.hasNext() )
56 const SplitData& anOutputSplitData = anOutputIter.next();
58 SplitDataList aList = SplitTwoData( anOutputSplitData, anInputSplitData );
59 aSplitDataList.append( aList );
61 anOutputSplitDataList = aSplitDataList;
66 if( theZoneList.Length() != 2 )
67 return aSplitDataList;
69 Handle(HYDROData_Zone) aZone1 = Handle(HYDROData_Zone)::DownCast( theZoneList.Value( 1 ) );
70 Handle(HYDROData_Zone) aZone2 = Handle(HYDROData_Zone)::DownCast( theZoneList.Value( 2 ) );
72 SplitData aSplitData1( aZone1->GetPainterPath(), aZone1->GetName() );
73 SplitData aSplitData2( aZone2->GetPainterPath(), aZone2->GetName() );
75 aSplitDataList = SplitTwoData( aSplitData1, aSplitData2 );
78 return anOutputSplitDataList;
81 HYDROGUI_SplitZonesTool::SplitDataList
82 HYDROGUI_SplitZonesTool::SplitTwoData( const SplitData& theData1,
83 const SplitData& theData2 )
85 SplitDataList aSplitDataList;
87 const QPainterPath& aPath1 = theData1.Path;
88 const QPainterPath& aPath2 = theData2.Path;
90 const QStringList& aZoneNames1 = theData1.ZoneNames;
91 const QStringList& aZoneNames2 = theData2.ZoneNames;
93 QPainterPath anIntersection = aPath1.intersected( aPath2 );
94 if( anIntersection.isEmpty() )
96 aSplitDataList.append( theData1 );
97 aSplitDataList.append( theData2 );
101 aSplitDataList.append( SplitData( anIntersection, aZoneNames1 + aZoneNames2 ) );
103 QPainterPath aPath1Sub = aPath1.subtracted( aPath2 );
104 if( !aPath1Sub.isEmpty() )
105 aSplitDataList.append( ExtractSeparateData( SplitData( aPath1Sub, aZoneNames1 ) ) );
107 QPainterPath aPath2Sub = aPath2.subtracted( aPath1 );
108 if( !aPath2Sub.isEmpty() )
109 aSplitDataList.append( ExtractSeparateData( SplitData( aPath2Sub, aZoneNames2 ) ) );
111 return aSplitDataList;
114 HYDROGUI_SplitZonesTool::SplitDataList
115 HYDROGUI_SplitZonesTool::ExtractSeparateData( const SplitData& theData )
117 SplitDataList aSplitDataList;
119 const QPainterPath& aBasePath = theData.Path;
120 const QStringList& aBaseZoneNames = theData.ZoneNames;
122 QList<QPainterPath> aPathList;
123 for( int i = 0, n = aBasePath.elementCount(); i < n; i++ )
125 const QPainterPath::Element anElement = aBasePath.elementAt( i );
126 switch( anElement.type )
128 case QPainterPath::MoveToElement:
129 aPathList.append( QPainterPath( QPointF( anElement.x, anElement.y ) ) );
131 case QPainterPath::LineToElement:
132 if( !aPathList.isEmpty() )
134 QPainterPath& aPath = aPathList.last();
135 aPath.lineTo( anElement.x, anElement.y );
138 case QPainterPath::CurveToElement: // currently not supported
144 if( aPathList.size() == 2 )
146 const QPainterPath& aPath1 = aPathList.first();
147 const QPainterPath& aPath2 = aPathList.last();
148 if( aPath1.contains( aPath2 ) || aPath2.contains( aPath1 ) )
150 aSplitDataList.append( theData );
151 return aSplitDataList;
155 QListIterator<QPainterPath> anIter( aPathList );
156 while( anIter.hasNext() )
158 const QPainterPath& aPath = anIter.next();
159 aSplitDataList.append( SplitData( aPath, aBaseZoneNames ) );
161 return aSplitDataList;