HYDROGUI_PrsZoneDriver.h
HYDROGUI_Shape.h
HYDROGUI_ShowHideOp.h
+ HYDROGUI_SplitZonesTool.h
HYDROGUI_Tool.h
HYDROGUI_TwoImagesDlg.h
HYDROGUI_TwoImagesOp.h
HYDROGUI_PrsZoneDriver.cxx
HYDROGUI_Shape.cxx
HYDROGUI_ShowHideOp.cxx
+ HYDROGUI_SplitZonesTool.cxx
HYDROGUI_Tool.cxx
HYDROGUI_TwoImagesDlg.cxx
HYDROGUI_TwoImagesOp.cxx
<?xml version="1.0" encoding="windows-1251"?>
<VisualStudioProject
ProjectType="Visual C++"
- Version="9.00"
+ Version="9,00"
Name="HYDROGUI"
ProjectGUID="{D11F0AD0-D002-4A22-A8E6-3F906379206F}"
RootNamespace="HYDROGUI"
RelativePath=".\HYDROGUI_ShowHideOp.cxx"
>
</File>
+ <File
+ RelativePath=".\HYDROGUI_SplitZonesTool.cxx"
+ >
+ </File>
<File
RelativePath=".\HYDROGUI_Tool.cxx"
>
/>
</FileConfiguration>
</File>
+ <File
+ RelativePath=".\HYDROGUI_SplitZonesTool.h"
+ >
+ </File>
<File
RelativePath=".\HYDROGUI_Tool.h"
>
<Tool
Name="VCCustomBuildTool"
Description="Generating moc_$(InputName).cxx"
- CommandLine="$(QTDIR)\bin\moc.exe $(InputPath) -o moc\moc_$(InputName).cxx"
+ CommandLine="$(QTDIR)\bin\moc.exe $(InputPath) -o moc\moc_$(InputName).cxx
"
Outputs="moc/moc_$(InputName).cxx"
/>
</FileConfiguration>
<Tool
Name="VCCustomBuildTool"
Description="Generating moc_$(InputName).cxx"
- CommandLine="$(QTDIR)\bin\moc.exe $(InputPath) -o moc\moc_$(InputName).cxx"
+ CommandLine="$(QTDIR)\bin\moc.exe $(InputPath) -o moc\moc_$(InputName).cxx
"
Outputs="moc/moc_$(InputName).cxx"
/>
</FileConfiguration>
void onViewPortMouseEvent( QGraphicsSceneMouseEvent* );
+ void onTestSplit(); // ouv: tmp, to delete
+
private:
void updateGV( const bool theIsInit = false,
const bool theIsForced = false );
#include "HYDROGUI_ObserveImageOp.h"
#include "HYDROGUI_PolylineOp.h"
#include "HYDROGUI_ShowHideOp.h"
+#include "HYDROGUI_SplitZonesTool.h"
#include "HYDROGUI_TwoImagesOp.h"
#include "HYDROGUI_UpdateFlags.h"
#include "HYDROGUI_UpdateImageOp.h"
createMenu( FuseImagesId, aHydroId, -1, -1 );
createMenu( CutImagesId, aHydroId, -1, -1 );
createMenu( SplitImageId, aHydroId, -1, -1 );
+
+ createMenu( separator(), aHydroId );
+ createMenu( TestSplitId, aHydroId, -1, -1 );
}
void HYDROGUI_Module::createPopups()
connect( anEditUndo, SIGNAL( triggered( int ) ), this, SLOT( onUndo( int ) ) );
connect( anEditRedo, SIGNAL( triggered( int ) ), this, SLOT( onRedo( int ) ) );
+
+ QAction* aTestSplit = new QAction( "Test split", application()->desktop() );
+ registerAction( TestSplitId, aTestSplit );
+ connect( aTestSplit, SIGNAL( triggered() ), this, SLOT( onTestSplit() ) );
}
void HYDROGUI_Module::updateUndoRedoControls()
return anOp;
}
+
+//-----------------------------------------------------------------------------
+// Test splitting
+//-----------------------------------------------------------------------------
+#include <HYDROData_Iterator.h>
+#include <HYDROGUI_Tool.h>
+void HYDROGUI_Module::onTestSplit()
+{
+ Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( getStudyId() );
+
+ aDocument->StartOperation();
+
+ HYDROData_SequenceOfObjects aZoneList;
+ HYDROData_Iterator anIterator( aDocument, KIND_ZONE );
+ for( ; anIterator.More(); anIterator.Next() )
+ aZoneList.Append( anIterator.Current() );
+
+ HYDROGUI_SplitZonesTool::SplitDataList aSplitDataList =
+ HYDROGUI_SplitZonesTool::SplitZones( aZoneList );
+
+ int anIndex = 0;
+ HYDROGUI_SplitZonesTool::SplitDataListIterator anIter( aSplitDataList );
+ while( anIter.hasNext() )
+ {
+ const HYDROGUI_SplitZonesTool::SplitData& aSplitData = anIter.next();
+ const QPainterPath& aPath = aSplitData.Path;
+ const QStringList& aZoneNames = aSplitData.ZoneNames;
+
+ Handle(HYDROData_Polyline) aPolyline =
+ Handle(HYDROData_Polyline)::DownCast( aDocument->CreateObject( KIND_POLYLINE ) );
+ if( !aPolyline.IsNull() )
+ {
+ aPolyline->SetName( QString( "SplitPolyline_%1" ).arg( ++anIndex ) );
+ aPolyline->setDimension( 2 );
+
+ QList<PolylineSection> aPolylineData;
+ for( int i = 0, n = aPath.elementCount(); i < n; i++ )
+ {
+ const QPainterPath::Element anElement = aPath.elementAt( i );
+ switch( anElement.type )
+ {
+ case QPainterPath::MoveToElement:
+ aPolylineData.append( PolylineSection() );
+ break;
+ case QPainterPath::LineToElement:
+ if( !aPolylineData.isEmpty() )
+ {
+ PolylineSection& aSection = aPolylineData.last();
+ aSection.myCoords << anElement.x;
+ aSection.myCoords << anElement.y;
+ }
+ break;
+ case QPainterPath::CurveToElement: // currently not supported
+ default:
+ break;
+ }
+ }
+ aPolyline->setPolylineData( aPolylineData );
+ }
+
+ Handle(HYDROData_Zone) aZone =
+ Handle(HYDROData_Zone)::DownCast( aDocument->CreateObject( KIND_ZONE ) );
+ if( !aZone.IsNull() )
+ {
+ aZone->SetName( QString( "SplitZone_%1" ).arg( anIndex ) );
+ aZone->SetPolyline( aPolyline );
+
+ aZone->SetBorderColor( Qt::black );
+
+ int aCounter = 0;
+ int aR = 0, aG = 0, aB = 0;
+ QStringListIterator aZoneNameIter( aZoneNames );
+ while( aZoneNameIter.hasNext() )
+ {
+ const QString& aZoneName = aZoneNameIter.next();
+ Handle(HYDROData_Zone) aRefZone = Handle(HYDROData_Zone)::DownCast(
+ HYDROGUI_Tool::FindObjectByName( this, aZoneName, KIND_ZONE ) );
+ if( !aRefZone.IsNull() )
+ {
+ QColor aRefColor = aRefZone->GetFillingColor();
+ aR += aRefColor.red();
+ aG += aRefColor.green();
+ aB += aRefColor.blue();
+ aCounter++;
+ }
+ }
+ if( aCounter > 0 )
+ {
+ QColor aFillingColor( aR / aCounter, aG / aCounter, aB / aCounter );
+ aZone->SetFillingColor( aFillingColor );
+ }
+ }
+ }
+
+ aDocument->CommitOperation();
+ update( UF_Model );
+}
ShowAllId,
HideId,
HideAllId,
+
+ TestSplitId
};
#endif
#include "HYDROGUI_PrsPolyline.h"
+#include <QPen>
+
//=======================================================================
// name : HYDROGUI_PrsPolyline
// Purpose : Constructor
void HYDROGUI_PrsPolyline::unselect()
{
GraphicsView_Object::unselect();
+
+ // ouv: tmp
+ QPen aPen = myPolylineItem->pen();
+ aPen.setColor( Qt::black );
+ aPen.setWidth( 1 );
+ myPolylineItem->setPen( aPen );
}
//================================================================
void HYDROGUI_PrsPolyline::setSelected( bool theState )
{
GraphicsView_Object::setSelected( theState );
+
+ // ouv: tmp
+ QPen aPen = myPolylineItem->pen();
+ aPen.setColor( theState ? Qt::red : Qt::black );
+ aPen.setWidth( theState ? 2 : 1 );
+ myPolylineItem->setPen( aPen );
}
}
QPainterPath aPath( myPath );
- aPath.setFillRule( Qt::WindingFill );
+ //aPath.setFillRule( Qt::WindingFill );
+ aPath.setFillRule( Qt::OddEvenFill ); // ouv: for correct drawing the paths with holes
myZoneItem->setPath( aPath );
myZoneItem->setBrush( QBrush( myFillingColor ) );
void HYDROGUI_PrsZone::unselect()
{
GraphicsView_Object::unselect();
+
+ // ouv: tmp
+ QPen aPen = myZoneItem->pen();
+ aPen.setColor( Qt::black );
+ aPen.setWidth( 1 );
+ myZoneItem->setPen( aPen );
}
//================================================================
void HYDROGUI_PrsZone::setSelected( bool theState )
{
GraphicsView_Object::setSelected( theState );
+
+ // ouv: tmp
+ QPen aPen = myZoneItem->pen();
+ aPen.setColor( theState ? Qt::red : Qt::black );
+ aPen.setWidth( theState ? 2 : 1 );
+ myZoneItem->setPen( aPen );
}
--- /dev/null
+// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "HYDROGUI_SplitZonesTool.h"
+
+#include <HYDROData_Zone.h>
+
+HYDROGUI_SplitZonesTool::SplitDataList
+HYDROGUI_SplitZonesTool::SplitZones( const HYDROData_SequenceOfObjects& theZoneList )
+{
+ SplitDataList anOutputSplitDataList;
+
+ SplitDataList anInputSplitDataList;
+ for( int anIndex = 1, aLength = theZoneList.Length(); anIndex <= aLength; anIndex++ )
+ {
+ Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( theZoneList.Value( anIndex ) );
+ if( !aZone.IsNull() )
+ {
+ SplitData aSplitData( aZone->GetPainterPath(), aZone->GetName() );
+ anInputSplitDataList.append( aSplitData );
+ }
+ }
+
+ SplitDataListIterator anInputIter( anInputSplitDataList );
+ while( anInputIter.hasNext() )
+ {
+ const SplitData& anInputSplitData = anInputIter.next();
+ if( anOutputSplitDataList.isEmpty() )
+ anOutputSplitDataList.append( anInputSplitData );
+ else
+ {
+ SplitDataList aSplitDataList;
+ SplitDataListIterator anOutputIter( anOutputSplitDataList );
+ while( anOutputIter.hasNext() )
+ {
+ const SplitData& anOutputSplitData = anOutputIter.next();
+
+ SplitDataList aList = SplitTwoData( anOutputSplitData, anInputSplitData );
+ aSplitDataList.append( aList );
+ }
+ anOutputSplitDataList = aSplitDataList;
+ }
+ }
+
+ /*
+ if( theZoneList.Length() != 2 )
+ return aSplitDataList;
+
+ Handle(HYDROData_Zone) aZone1 = Handle(HYDROData_Zone)::DownCast( theZoneList.Value( 1 ) );
+ Handle(HYDROData_Zone) aZone2 = Handle(HYDROData_Zone)::DownCast( theZoneList.Value( 2 ) );
+
+ SplitData aSplitData1( aZone1->GetPainterPath(), aZone1->GetName() );
+ SplitData aSplitData2( aZone2->GetPainterPath(), aZone2->GetName() );
+
+ aSplitDataList = SplitTwoData( aSplitData1, aSplitData2 );
+ */
+
+ return anOutputSplitDataList;
+}
+
+HYDROGUI_SplitZonesTool::SplitDataList
+HYDROGUI_SplitZonesTool::SplitTwoData( const SplitData& theData1,
+ const SplitData& theData2 )
+{
+ SplitDataList aSplitDataList;
+
+ const QPainterPath& aPath1 = theData1.Path;
+ const QPainterPath& aPath2 = theData2.Path;
+
+ const QStringList& aZoneNames1 = theData1.ZoneNames;
+ const QStringList& aZoneNames2 = theData2.ZoneNames;
+
+ QPainterPath anIntersection = aPath1.intersected( aPath2 );
+ if( anIntersection.isEmpty() )
+ {
+ aSplitDataList.append( theData1 );
+ aSplitDataList.append( theData2 );
+ }
+ else
+ {
+ aSplitDataList.append( SplitData( anIntersection, aZoneNames1 + aZoneNames2 ) );
+
+ QPainterPath aPath1Sub = aPath1.subtracted( aPath2 );
+ if( !aPath1Sub.isEmpty() )
+ aSplitDataList.append( ExtractSeparateData( SplitData( aPath1Sub, aZoneNames1 ) ) );
+
+ QPainterPath aPath2Sub = aPath2.subtracted( aPath1 );
+ if( !aPath2Sub.isEmpty() )
+ aSplitDataList.append( ExtractSeparateData( SplitData( aPath2Sub, aZoneNames2 ) ) );
+ }
+ return aSplitDataList;
+}
+
+HYDROGUI_SplitZonesTool::SplitDataList
+HYDROGUI_SplitZonesTool::ExtractSeparateData( const SplitData& theData )
+{
+ SplitDataList aSplitDataList;
+
+ const QPainterPath& aBasePath = theData.Path;
+ const QStringList& aBaseZoneNames = theData.ZoneNames;
+
+ QList<QPainterPath> aPathList;
+ for( int i = 0, n = aBasePath.elementCount(); i < n; i++ )
+ {
+ const QPainterPath::Element anElement = aBasePath.elementAt( i );
+ switch( anElement.type )
+ {
+ case QPainterPath::MoveToElement:
+ aPathList.append( QPainterPath( QPointF( anElement.x, anElement.y ) ) );
+ break;
+ case QPainterPath::LineToElement:
+ if( !aPathList.isEmpty() )
+ {
+ QPainterPath& aPath = aPathList.last();
+ aPath.lineTo( anElement.x, anElement.y );
+ }
+ break;
+ case QPainterPath::CurveToElement: // currently not supported
+ default:
+ break;
+ }
+ }
+
+ if( aPathList.size() == 2 )
+ {
+ const QPainterPath& aPath1 = aPathList.first();
+ const QPainterPath& aPath2 = aPathList.last();
+ if( aPath1.contains( aPath2 ) || aPath2.contains( aPath1 ) )
+ {
+ aSplitDataList.append( theData );
+ return aSplitDataList;
+ }
+ }
+
+ QListIterator<QPainterPath> anIter( aPathList );
+ while( anIter.hasNext() )
+ {
+ const QPainterPath& aPath = anIter.next();
+ aSplitDataList.append( SplitData( aPath, aBaseZoneNames ) );
+ }
+ return aSplitDataList;
+}
--- /dev/null
+// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#ifndef HYDROGUI_SPLITZONESTOOL_H
+#define HYDROGUI_SPLITZONESTOOL_H
+
+#include <HYDROData_Object.h>
+
+#include <QPainterPath>
+#include <QStringList>
+
+/**
+ * \class HYDROGUI_SplitZonesTool
+ * \brief This class contains methods used for splitting zones
+ * into non-intersected regions.
+ */
+class HYDROGUI_SplitZonesTool
+{
+public:
+ struct SplitData
+ {
+ QPainterPath Path;
+ QStringList ZoneNames;
+
+ SplitData( const QPainterPath& thePath,
+ const QStringList& theZoneNames ) :
+ Path( thePath ), ZoneNames( theZoneNames ) {}
+
+ SplitData( const QPainterPath& thePath,
+ const QString& theZoneName ) :
+ Path( thePath ), ZoneNames( theZoneName ) {}
+ };
+
+ typedef QList <SplitData> SplitDataList;
+ typedef QListIterator<SplitData> SplitDataListIterator;
+
+public:
+ static SplitDataList SplitZones( const HYDROData_SequenceOfObjects& theZoneList );
+
+private:
+ static SplitDataList SplitTwoData( const SplitData& theData1,
+ const SplitData& theData2 );
+
+ static SplitDataList ExtractSeparateData( const SplitData& theData );
+};
+
+#endif