#include "HYDROData_Document.h"
#include "HYDROData_Iterator.h"
#include "HYDROData_Polyline.h"
+#include "HYDROData_Zone.h"
#include <TDataStd_ReferenceList.hxx>
return Handle(HYDROData_Polyline)::DownCast(
GetReferenceObject( DataTag_BoundaryPolyline ) );
}
+
+void HYDROData_Calculation::RemoveBoundaryPolyline()
+{
+ ClearReferenceObjects( DataTag_BoundaryPolyline );
+}
+
+int HYDROData_Calculation::NbZones() const
+{
+ return NbReferenceObjects( DataTag_Zone );
+}
+
+void HYDROData_Calculation::AddZone( const Handle(HYDROData_Zone)& theZone )
+{
+ AddReferenceObject( theZone, DataTag_Zone );
+}
+
+void HYDROData_Calculation::SetZone( const int theIndex,
+ const Handle(HYDROData_Zone)& theZone )
+{
+ SetReferenceObject( theZone, DataTag_Zone, theIndex );
+}
+
+void HYDROData_Calculation::SetZones( const HYDROData_SequenceOfObjects& theZones )
+{
+ SetReferenceObjects( theZones, DataTag_Zone );
+}
+
+Handle(HYDROData_Zone) HYDROData_Calculation::GetZone( const int theIndex ) const
+{
+ return Handle(HYDROData_Zone)::DownCast(
+ GetReferenceObject( DataTag_Zone, theIndex ) );
+}
+
+HYDROData_SequenceOfObjects HYDROData_Calculation::GetZones() const
+{
+ return GetReferenceObjects( DataTag_Zone );
+}
+
+void HYDROData_Calculation::RemoveZones()
+{
+ ClearReferenceObjects( DataTag_Zone );
+}
+
+int HYDROData_Calculation::NbSplittedZones() const
+{
+ return NbReferenceObjects( DataTag_SplittedZone );
+}
+
+void HYDROData_Calculation::AddSplittedZone( const Handle(HYDROData_Zone)& theZone )
+{
+ AddReferenceObject( theZone, DataTag_SplittedZone );
+}
+
+void HYDROData_Calculation::SetSplittedZone( const int theIndex,
+ const Handle(HYDROData_Zone)& theZone )
+{
+ SetReferenceObject( theZone, DataTag_SplittedZone, theIndex );
+}
+
+void HYDROData_Calculation::SetSplittedZones( const HYDROData_SequenceOfObjects& theZones )
+{
+ SetReferenceObjects( theZones, DataTag_SplittedZone );
+}
+
+Handle(HYDROData_Zone) HYDROData_Calculation::GetSplittedZone( const int theIndex ) const
+{
+ return Handle(HYDROData_Zone)::DownCast(
+ GetReferenceObject( DataTag_SplittedZone, theIndex ) );
+}
+
+HYDROData_SequenceOfObjects HYDROData_Calculation::GetSplittedZones() const
+{
+ return GetReferenceObjects( DataTag_SplittedZone );
+}
+
+void HYDROData_Calculation::RemoveSplittedZones()
+{
+ ClearReferenceObjects( DataTag_SplittedZone );
+}
+
class QFile;
class Handle(HYDROData_Polyline);
+class Handle(HYDROData_Zone);
DEFINE_STANDARD_HANDLE(HYDROData_Calculation, HYDROData_Object)
{
DataTag_First = HYDROData_Object::DataTag_First + 100, ///< first tag, to reserve
DataTag_BoundaryPolyline, ///< reference boundary polyline
+ DataTag_Zone, ///< reference zones
+ DataTag_SplittedZone ///< reference splitted zones
};
public:
public:
// Public methods to work with Calculation
+ /**
+ * Sets boundary polyline for calculation case.
+ */
HYDRODATA_EXPORT virtual void SetBoundaryPolyline( const Handle(HYDROData_Polyline)& thePolyline );
+ /**
+ * Returns boundary polyline of calculation case.
+ */
HYDRODATA_EXPORT virtual Handle(HYDROData_Polyline) GetBoundaryPolyline() const;
+ /**
+ * Removes boundary polyline of calculation case.
+ */
+ HYDRODATA_EXPORT virtual void RemoveBoundaryPolyline();
+
+
+ /**
+ * Returns number of refrence zones for calculation case.
+ */
+ HYDRODATA_EXPORT virtual int NbZones() const;
+
+ /**
+ * Add new one refrence zone for calculation case.
+ */
+ HYDRODATA_EXPORT virtual void AddZone( const Handle(HYDROData_Zone)& theZone );
+
+ /**
+ * Replace the refrence zone for calculation case.
+ */
+ HYDRODATA_EXPORT virtual void SetZone( const int theIndex,
+ const Handle(HYDROData_Zone)& theBathymetry );
+
+ /**
+ * Sets the refrence zones for calculation case.
+ */
+ HYDRODATA_EXPORT virtual void SetZones( const HYDROData_SequenceOfObjects& theZones );
+
+ /**
+ * Returns refrence zone of calculation case by index.
+ */
+ HYDRODATA_EXPORT virtual Handle(HYDROData_Zone) GetZone( const int theIndex ) const;
+
+ /**
+ * Returns all refrence zone of calculation case.
+ */
+ HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetZones() const;
+
+ /**
+ * Removes all refrence zone of calculation case.
+ */
+ HYDRODATA_EXPORT virtual void RemoveZones();
+
+
+ /**
+ * Returns number of splitted zones for calculation case.
+ */
+ HYDRODATA_EXPORT virtual int NbSplittedZones() const;
+
+ /**
+ * Add new one splitted zone for calculation case.
+ */
+ HYDRODATA_EXPORT virtual void AddSplittedZone( const Handle(HYDROData_Zone)& theZone );
+
+ /**
+ * Replace the splitted zone for calculation case.
+ */
+ HYDRODATA_EXPORT virtual void SetSplittedZone( const int theIndex,
+ const Handle(HYDROData_Zone)& theBathymetry );
+
+ /**
+ * Sets the refrence zones for calculation case.
+ */
+ HYDRODATA_EXPORT virtual void SetSplittedZones( const HYDROData_SequenceOfObjects& theZones );
+
+ /**
+ * Returns splitted zone of calculation case by index.
+ */
+ HYDRODATA_EXPORT virtual Handle(HYDROData_Zone) GetSplittedZone( const int theIndex ) const;
+
+ /**
+ * Returns all splitted zone of calculation case.
+ */
+ HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetSplittedZones() const;
+
+ /**
+ * Removes all splitted refrence zone of calculation case.
+ */
+ HYDRODATA_EXPORT virtual void RemoveSplittedZones();
+
protected:
friend class HYDROData_Iterator;
}
}
+void HYDROData_Object::SetReferenceObjects( const HYDROData_SequenceOfObjects& theObjects,
+ const int theTag )
+{
+ ClearReferenceObjects( theTag );
+ if ( theObjects.IsEmpty() )
+ return;
+
+ HYDROData_SequenceOfObjects::Iterator anIter( theObjects );
+ for ( ; anIter.More(); anIter.Next() )
+ AddReferenceObject( anIter.Value(), theTag );
+}
+
Handle(HYDROData_Object) HYDROData_Object::GetReferenceObject( const int theTag,
const int theIndex ) const
{
const int theTag = 0,
const int theIndex = 0 );
+ /**
+ * Internal method that used to store the reference object label attribute
+ * \param theObjects sequence with pointers to reference objects
+ * \param theTag tag of a label to store attribute (for 0 this is myLab)
+ */
+ void SetReferenceObjects( const HYDROData_SequenceOfObjects& theObjects,
+ const int theTag = 0 );
+
/**
* Internal method that used to retreive the reference object(s) attribute
* \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
#include <QLabel>
#include <QLayout>
#include <QLineEdit>
+#include <QListWidget>
#include <QPicture>
+#include <QPushButton>
#include <QToolButton>
HYDROGUI_CalculationDlg::HYDROGUI_CalculationDlg( HYDROGUI_Module* theModule, const QString& theTitle )
aNameLayout->addWidget( new QLabel( tr( "NAME" ), myObjectNameGroup ) );
aNameLayout->addWidget( myObjectName );
+
+ // Calculation boundary line
QGroupBox* aBndGroup = new QGroupBox( tr( "CALCULATION_BOUNDARY" ), mainFrame() );
myBndPolyline = new HYDROGUI_ObjSelector( theModule, KIND_POLYLINE, aBndGroup );
aBndLayout->addWidget( new QLabel( tr( "BOUNDARY_POLYLINE" ), aBndGroup ) );
aBndLayout->addWidget( myBndPolyline );
+
+ // Calculation zones
+ QGroupBox* aZonesGroup = new QGroupBox( tr( "CALCULATION_ZONES" ), mainFrame() );
+
+ myZones = new QListWidget( aZonesGroup );
+ myZones->setSelectionMode( QListWidget::SingleSelection );
+ myZones->setEditTriggers( QListWidget::NoEditTriggers );
+ myZones->setViewMode( QListWidget::ListMode );
+
+ mySplittedZones = new QListWidget( aZonesGroup );
+ mySplittedZones->setSelectionMode( QListWidget::SingleSelection );
+ mySplittedZones->setEditTriggers( QListWidget::NoEditTriggers );
+ mySplittedZones->setViewMode( QListWidget::ListMode );
+
+ mySplittedZonesPrefix = new QLineEdit( aZonesGroup );
+
+ QPushButton* aSplitBtn = new QPushButton( tr( "SPLIT_REFERENCE_ZONES" ), aZonesGroup );
+
+ QGridLayout* aZonesLayout = new QGridLayout( aZonesGroup );
+ aZonesLayout->setMargin( 5 );
+ aZonesLayout->setSpacing( 5 );
+ aZonesLayout->addWidget( new QLabel( tr( "CALCULATION_REFERENCE_ZONES" ), aZonesGroup ), 0, 0, 1, 2 );
+ aZonesLayout->addWidget( myZones, 1, 0, 1, 2 );
+ aZonesLayout->addWidget( new QLabel( tr( "CALCULATION_SPLITTED_ZONES" ), aZonesGroup ), 2, 0, 1, 2 );
+ aZonesLayout->addWidget( mySplittedZones, 3, 0, 1, 2 );
+ aZonesLayout->addWidget( new QLabel( tr( "PREFIX_SPLITTED_ZONES" ), aZonesGroup ), 4, 0 );
+ aZonesLayout->addWidget( mySplittedZonesPrefix, 4, 1 );
+ aZonesLayout->addWidget( aSplitBtn, 5, 0, 1, 2 );
+
// Common
addWidget( myObjectNameGroup );
addWidget( aBndGroup );
+ addWidget( aZonesGroup );
addStretch();
+
+
+ // Connect signals and slots
+ connect( aSplitBtn, SIGNAL( clicked( bool ) ), this, SIGNAL( SplitZones() ) );
}
HYDROGUI_CalculationDlg::~HYDROGUI_CalculationDlg()
myObjectName->clear();
myBndPolyline->Clear();
+
+ myZones->clear();
+ mySplittedZones->clear();
+
+ setSplitZonesPrefix( tr( "DEFAULT_PREFIX_SPLITTED_ZONES" ) );
}
void HYDROGUI_CalculationDlg::setObjectName( const QString& theName )
return myBndPolyline->GetName();
}
+void HYDROGUI_CalculationDlg::setZones( const QStringList& theZones )
+{
+ myZones->clear();
+
+ for ( int i = 0, n = theZones.length(); i < n; ++i )
+ {
+ QString aZoneName = theZones.at( i );
+
+ QListWidgetItem* aListItem = new QListWidgetItem( aZoneName, myZones );
+ aListItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable );
+ aListItem->setCheckState( Qt::Unchecked );
+ }
+}
+
+void HYDROGUI_CalculationDlg::setSelectedZones( const QStringList& theZones )
+{
+ for ( int i = 0, n = theZones.length(); i < n; ++i )
+ {
+ QString aZoneName = theZones.at( i );
+ QList<QListWidgetItem *> anItems =
+ myZones->findItems( aZoneName, Qt::MatchFixedString | Qt::MatchCaseSensitive );
+ if ( anItems.isEmpty() )
+ continue;
+
+ QListWidgetItem* aListItem = anItems.first();
+ if ( !aListItem )
+ continue;
+
+ aListItem->setCheckState( Qt::Checked );
+ }
+}
+
+QStringList HYDROGUI_CalculationDlg::getSelectedZones() const
+{
+ QStringList aResList;
+
+ for ( int i = 0, n = myZones->count(); i < n; ++i )
+ {
+ QListWidgetItem* aListItem = myZones->item( i );
+ if ( !aListItem || aListItem->checkState() != Qt::Checked )
+ continue;
+
+ QString aSelZoneName = aListItem->text();
+ aResList.append( aSelZoneName );
+ }
+
+ return aResList;
+}
+
+void HYDROGUI_CalculationDlg::setSplittedZones( const QStringList& theZones )
+{
+ mySplittedZones->clear();
+
+ for ( int i = 0, n = theZones.length(); i < n; ++i )
+ {
+ QString aZoneName = theZones.at( i );
+
+ QListWidgetItem* aListItem = new QListWidgetItem( aZoneName, mySplittedZones );
+ aListItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
+ }
+}
+
+QStringList HYDROGUI_CalculationDlg::getSplittedZones() const
+{
+ QStringList aResList;
+
+ for ( int i = 0, n = mySplittedZones->count(); i < n; ++i )
+ {
+ QListWidgetItem* aListItem = mySplittedZones->item( i );
+ if ( !aListItem )
+ continue;
+
+ QString aSplittedZoneName = aListItem->text();
+ aResList.append( aSplittedZoneName );
+ }
+
+ return aResList;
+}
+
+void HYDROGUI_CalculationDlg::setSplitZonesPrefix( const QString& theName )
+{
+ mySplittedZonesPrefix->setText( theName );
+}
+
+QString HYDROGUI_CalculationDlg::getSplitZonesPrefix() const
+{
+ QString aPrefix = mySplittedZonesPrefix->text();
+ if ( aPrefix.isEmpty() )
+ aPrefix = tr( "DEFAULT_PREFIX_SPLITTED_ZONES" );
+ return aPrefix;
+}
class HYDROGUI_ObjSelector;
class QGroupBox;
class QLineEdit;
+class QListWidget;
class HYDROGUI_CalculationDlg : public HYDROGUI_InputPanel
{
void setPolylineName( const QString& theName );
QString getPolylineName() const;
+ void setZones( const QStringList& theZones );
+ void setSelectedZones( const QStringList& theZones );
+ QStringList getSelectedZones() const;
+
+ void setSplittedZones( const QStringList& theZones );
+ QStringList getSplittedZones() const;
+
+ void setSplitZonesPrefix( const QString& theName );
+ QString getSplitZonesPrefix() const;
+
+signals:
+ void SplitZones();
+
private:
QGroupBox* myObjectNameGroup;
QLineEdit* myObjectName;
HYDROGUI_ObjSelector* myBndPolyline;
+
+ QListWidget* myZones;
+ QListWidget* mySplittedZones;
+ QLineEdit* mySplittedZonesPrefix;
};
#endif
#include "HYDROGUI_UpdateFlags.h"
#include <HYDROData_Polyline.h>
+#include <HYDROData_Iterator.h>
+#include <HYDROData_Zone.h>
+
+#include <OCCViewer_ViewManager.h>
+#include <OCCViewer_ViewModel.h>
#include <LightApp_Application.h>
#include <LightApp_UpdateFlags.h>
+#include <QApplication>
+
HYDROGUI_CalculationOp::HYDROGUI_CalculationOp( HYDROGUI_Module* theModule, bool theIsEdit )
: HYDROGUI_Operation( theModule ),
- myIsEdit( theIsEdit )
+ myIsEdit( theIsEdit ),
+ myActiveViewManager( NULL ),
+ myPreviewViewManager( NULL )
{
setName( myIsEdit ? tr( "EDIT_CALCULATION" ) : tr( "CREATE_CALCULATION" ) );
}
HYDROGUI_CalculationOp::~HYDROGUI_CalculationOp()
{
+ closePreview();
}
void HYDROGUI_CalculationOp::startOperation()
if ( !aPanel )
return;
+ mySplittedZones.clear();
aPanel->reset();
QString anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), "Case" );
+ QStringList aSelectedZones, aSplittedZones;
+
myEditedObject.Nullify();
if ( myIsEdit )
{
QString aPolylineName = aBoundaryPolyline->GetName();
aPanel->setPolylineName( aPolylineName );
}
+
+ HYDROData_SequenceOfObjects aRefZones = myEditedObject->GetZones();
+ HYDROData_SequenceOfObjects::Iterator anIter( aRefZones );
+ for ( ; anIter.More(); anIter.Next() )
+ {
+ Handle(HYDROData_Zone) aRefZone =
+ Handle(HYDROData_Zone)::DownCast( anIter.Value() );
+ if ( aRefZone.IsNull() )
+ continue;
+
+ QString aRefZoneName = aRefZone->GetName();
+ if ( aRefZoneName.isEmpty() )
+ continue;
+
+ aSelectedZones.append( aRefZoneName );
+ }
+
+ HYDROData_SequenceOfObjects aSplitZones = myEditedObject->GetSplittedZones();
+ anIter.Init( aSplitZones );
+ for ( ; anIter.More(); anIter.Next() )
+ {
+ Handle(HYDROData_Zone) aSplitZone =
+ Handle(HYDROData_Zone)::DownCast( anIter.Value() );
+ if ( aSplitZone.IsNull() )
+ continue;
+
+ QString aSplitZoneName = aSplitZone->GetName();
+ if ( aSplitZoneName.isEmpty() )
+ continue;
+
+ aSplittedZones.append( aSplitZoneName );
+ }
}
}
+ // collect information about existing zones
+ QStringList aZones;
+
+ HYDROData_Iterator anIter( doc(), KIND_ZONE );
+ for ( ; anIter.More(); anIter.Next() )
+ {
+ Handle(HYDROData_Zone) aZoneObj =
+ Handle(HYDROData_Zone)::DownCast( anIter.Current() );
+ if ( aZoneObj.IsNull() )
+ continue;
+
+ QString aZoneName = aZoneObj->GetName();
+ if ( aZoneName.isEmpty() )
+ continue;
+
+ aZones.append( aZoneName );
+ }
+
aPanel->setObjectName( anObjectName );
+
+ aPanel->setZones( aZones );
+ aPanel->setSelectedZones( aSelectedZones );
+ aPanel->setSplittedZones( aSplittedZones );
}
void HYDROGUI_CalculationOp::abortOperation()
{
+ closePreview();
+
HYDROGUI_Operation::abortOperation();
}
void HYDROGUI_CalculationOp::commitOperation()
{
+ closePreview();
+
HYDROGUI_Operation::commitOperation();
}
HYDROGUI_InputPanel* HYDROGUI_CalculationOp::createInputPanel() const
{
HYDROGUI_CalculationDlg* aPanel = new HYDROGUI_CalculationDlg( module(), getName() );
+
+ // Connect signals and slots
+ connect( aPanel, SIGNAL( SplitZones() ), this, SLOT( onSplitZones() ) );
+
return aPanel;
}
}
}
+ Handle(HYDROData_Document) aDocument = doc();
+
Handle(HYDROData_Calculation) aCalculObj = myIsEdit ? myEditedObject :
- Handle(HYDROData_Calculation)::DownCast( doc()->CreateObject( KIND_CALCULATION ) );
+ Handle(HYDROData_Calculation)::DownCast( aDocument->CreateObject( KIND_CALCULATION ) );
if ( aCalculObj.IsNull() )
return false;
aCalculObj->SetName( anObjectName );
- Handle(HYDROData_Polyline) aBndPolyline;
-
QString aPolylineName = aPanel->getPolylineName();
- if ( !aPolylineName.isEmpty() )
- {
- aBndPolyline = Handle(HYDROData_Polyline)::DownCast(
+ Handle(HYDROData_Polyline) aBndPolyline = Handle(HYDROData_Polyline)::DownCast(
HYDROGUI_Tool::FindObjectByName( module(), aPolylineName, KIND_POLYLINE ) );
- }
aCalculObj->SetBoundaryPolyline( aBndPolyline );
+ QStringList aRefZoneNames = aPanel->getSelectedZones();
+ HYDROData_SequenceOfObjects aRefZones =
+ HYDROGUI_Tool::FindObjectsByNames( module(), aRefZoneNames, KIND_ZONE );
+
+ aCalculObj->SetZones( aRefZones );
+
+ HYDROData_SequenceOfObjects aSplittedZones;
+
+ SplittedZonesList::iterator anIter = mySplittedZones.begin();
+ for ( ; anIter != mySplittedZones.end(); ++anIter )
+ {
+ const SplittedZone& aSplittedZone = *anIter;
+
+ Handle(HYDROData_Polyline) aPolyline =
+ Handle(HYDROData_Polyline)::DownCast( aDocument->CreateObject( KIND_POLYLINE ) );
+ Handle(HYDROData_Zone) aDtaZone =
+ Handle(HYDROData_Zone)::DownCast( aDocument->CreateObject( KIND_ZONE ) );
+
+ if( aPolyline.IsNull() || aDtaZone.IsNull() )
+ continue;
+
+ // Fill the polyline data
+ aPolyline->SetName( aSplittedZone.PolylineName );
+ aPolyline->setDimension( 2 );
+
+ QList<PolylineSection> aPolylineData;
+ for( int i = 0, n = aSplittedZone.SplitData.Path.elementCount(); i < n; i++ )
+ {
+ const QPainterPath::Element anElement = aSplittedZone.SplitData.Path.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 );
+
+ // Fill the zone data
+ aDtaZone->SetName( aSplittedZone.ZoneName );
+ aDtaZone->SetPolyline( aPolyline );
+ aDtaZone->SetBorderColor( aSplittedZone.BorderColor );
+ aDtaZone->SetFillingColor( aSplittedZone.FillingColor );
+
+ aSplittedZones.Append( aDtaZone );
+ }
+
+ aCalculObj->SetSplittedZones( aSplittedZones );
+
theUpdateFlags = UF_Model;
return true;
}
+void HYDROGUI_CalculationOp::onSplitZones()
+{
+ mySplittedZones.clear();
+
+ HYDROGUI_CalculationDlg* aPanel =
+ ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
+ if ( !aPanel )
+ return;
+
+ QApplication::setOverrideCursor( Qt::WaitCursor );
+
+ QString aPolylineName = aPanel->getPolylineName();
+ Handle(HYDROData_Polyline) aBndPolyline = Handle(HYDROData_Polyline)::DownCast(
+ HYDROGUI_Tool::FindObjectByName( module(), aPolylineName, KIND_POLYLINE ) );
+
+ QStringList aZoneNames = aPanel->getSelectedZones();
+ HYDROData_SequenceOfObjects aZones =
+ HYDROGUI_Tool::FindObjectsByNames( module(), aZoneNames, KIND_ZONE );
+
+ QStringList aResSplittedZones;
+
+ HYDROGUI_SplitZonesTool::SplitDataList aSplittedZones =
+ HYDROGUI_SplitZonesTool::SplitZones( aZones, aBndPolyline );
+
+ QString aSplitZonesPrefix = aPanel->getSplitZonesPrefix();
+ QStringList aUsedNames;
+
+ HYDROGUI_SplitZonesTool::SplitDataListIterator anIter( aSplittedZones );
+ while( anIter.hasNext() )
+ {
+ SplittedZone aSplittedZone;
+ aSplittedZone.SplitData = anIter.next();
+
+ aSplittedZone.FillingColor = HYDROGUI_Tool::GenerateFillingColor( module(), aSplittedZone.SplitData.ZoneNames );
+ aSplittedZone.BorderColor = QColor( HYDROData_Zone::DefaultBorderColor() );
+
+ aSplittedZone.ZoneName = HYDROGUI_Tool::GenerateObjectName( module(), aSplitZonesPrefix + "Zone", aUsedNames );
+ aSplittedZone.PolylineName = HYDROGUI_Tool::GenerateObjectName( module(), aSplitZonesPrefix + "Poly", aUsedNames );
+
+ aUsedNames.append( aSplittedZone.ZoneName );
+ aUsedNames.append( aSplittedZone.PolylineName );
+
+ aResSplittedZones.append( aSplittedZone.ZoneName );
+
+ mySplittedZones.append( aSplittedZone );
+ }
+
+ aPanel->setSplittedZones( aResSplittedZones );
+
+ createPreview();
+
+ QApplication::restoreOverrideCursor();
+}
+
+void HYDROGUI_CalculationOp::createPreview()
+{
+ LightApp_Application* anApp = module()->getApp();
+
+ if ( !myActiveViewManager )
+ {
+ myActiveViewManager = anApp->activeViewManager();
+ }
+
+ if ( !myPreviewViewManager )
+ {
+ myPreviewViewManager = ::qobject_cast<OCCViewer_ViewManager*>(
+ anApp->createViewManager( OCCViewer_Viewer::Type() ) );
+ if ( myPreviewViewManager )
+ {
+ connect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
+ this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
+
+ module()->setViewManagerRole( myPreviewViewManager, HYDROGUI_Module::VMR_PreviewCaseZones );
+ myPreviewViewManager->setTitle( tr( "PREVIEW_CASE_ZONES" ) );
+ }
+ }
+
+ if ( !myPreviewViewManager )
+ return;
+
+ if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
+ {
+ Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
+ if ( !aCtx.IsNull() )
+ {
+ SplittedZonesList::iterator anIter = mySplittedZones.begin();
+ for ( ; anIter != mySplittedZones.end(); ++anIter )
+ {
+ SplittedZone& aSplittedZone = *anIter;
+ if ( aSplittedZone.Shape )
+ delete aSplittedZone.Shape;
+
+ aSplittedZone.Shape = new HYDROGUI_Shape( aCtx );
+
+ aSplittedZone.Shape->setFillingColor( aSplittedZone.FillingColor, false );
+ aSplittedZone.Shape->setBorderColor( aSplittedZone.BorderColor, false );
+ aSplittedZone.Shape->setPath( aSplittedZone.SplitData.Path, true );
+ }
+ }
+ }
+}
+
+void HYDROGUI_CalculationOp::onLastViewClosed( SUIT_ViewManager* theViewManager )
+{
+ closePreview();
+}
+
+void HYDROGUI_CalculationOp::closePreview()
+{
+ SplittedZonesList::iterator anIter= mySplittedZones.begin();
+ for ( ; anIter != mySplittedZones.end(); ++anIter )
+ {
+ SplittedZone& aSplittedZone = *anIter;
+ if ( aSplittedZone.Shape )
+ {
+ delete aSplittedZone.Shape;
+ aSplittedZone.Shape = NULL;
+ }
+ }
+
+ if( myPreviewViewManager )
+ {
+ disconnect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
+ this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
+
+ module()->getApp()->removeViewManager( myPreviewViewManager ); // myPreviewViewManager is deleted here
+ myPreviewViewManager = NULL;
+ }
+
+ if( myActiveViewManager )
+ {
+ HYDROGUI_Tool::SetActiveViewManager( module(), myActiveViewManager );
+ myActiveViewManager = NULL;
+ }
+}
+
#include "HYDROGUI_Operation.h"
+#include "HYDROGUI_SplitZonesTool.h"
+#include "HYDROGUI_Shape.h"
+
#include <HYDROData_Calculation.h>
+class SUIT_ViewManager;
+class OCCViewer_ViewManager;
+
class HYDROGUI_CalculationOp : public HYDROGUI_Operation
{
Q_OBJECT
+ struct SplittedZone
+ {
+ QString ZoneName;
+ QString PolylineName;
+ QColor FillingColor;
+ QColor BorderColor;
+ HYDROGUI_SplitZonesTool::SplitData SplitData;
+ HYDROGUI_Shape* Shape;
+
+ SplittedZone()
+ : Shape( NULL ),
+ FillingColor( Qt::green ),
+ BorderColor( Qt::transparent )
+ { }
+
+ ~SplittedZone()
+ {
+ if ( Shape )
+ {
+ delete Shape;
+ Shape = NULL;
+ }
+ }
+ };
+
+ typedef QList<SplittedZone> SplittedZonesList;
+
public:
HYDROGUI_CalculationOp( HYDROGUI_Module* theModule, bool theIsEdit );
virtual ~HYDROGUI_CalculationOp();
virtual bool processApply( int& theUpdateFlags, QString& theErrorMsg );
+protected slots:
+ void onSplitZones();
+ void onLastViewClosed( SUIT_ViewManager* );
+
+private:
+ void createPreview();
+ void closePreview();
+
private:
bool myIsEdit;
Handle(HYDROData_Calculation) myEditedObject;
+ SUIT_ViewManager* myActiveViewManager;
+
+ OCCViewer_ViewManager* myPreviewViewManager;
+ SplittedZonesList mySplittedZones;
};
#endif
LightApp_DataObject* HYDROGUI_DataModel::createObject( SUIT_DataObject* theParent,
Handle(HYDROData_Object) theModelObject,
- const QString& theParentEntry )
+ const QString& theParentEntry,
+ const bool theIsBuildTree )
{
HYDROGUI_DataObject* aResObj =
new HYDROGUI_DataObject( theParent, theModelObject, theParentEntry );
- buildObjectTree( theParent, aResObj, theParentEntry );
+
+ if ( theIsBuildTree )
+ {
+ buildObjectTree( theParent, aResObj, theParentEntry );
+ }
+
return aResObj;
}
LightApp_DataObject* HYDROGUI_DataModel::createObject( SUIT_DataObject* theParent,
const QString& theName,
- const QString& theParentEntry )
+ const QString& theParentEntry )
{
return new HYDROGUI_NamedObject( theParent, theName, theParentEntry );
}
{
Handle(HYDROData_Object) aRefObj = anImageObj->Reference( anIndex );
if ( !aRefObj.IsNull() && !aRefObj->IsRemoved() )
- createObject( aGuiObj, aRefObj, aGuiObj->entry() );
+ createObject( aGuiObj, aRefObj, aGuiObj->entry(), false );
}
}
else if ( anObjectKind == KIND_ZONE )
Handle(HYDROData_Zone) aZoneObj =
Handle(HYDROData_Zone)::DownCast( aDataObj );
- LightApp_DataObject* aPolylineSect = createObject( aGuiObj, tr( "ZONE_POLYLINE" ), aGuiObj->entry() );
+ LightApp_DataObject* aPolylineSect =
+ createObject( aGuiObj, tr( "ZONE_POLYLINE" ), aGuiObj->entry() );
Handle(HYDROData_Polyline) aPolyline = aZoneObj->GetPolyline();
if ( !aPolyline.IsNull() && !aPolyline->IsRemoved() )
- createObject( aPolylineSect, aPolyline, aGuiObj->entry() );
+ createObject( aPolylineSect, aPolyline, aGuiObj->entry(), false );
- LightApp_DataObject* aBathsSect = createObject( aGuiObj, tr( "ZONE_BATHYMETRIES" ), aGuiObj->entry() );
+ LightApp_DataObject* aBathsSect =
+ createObject( aGuiObj, tr( "ZONE_BATHYMETRIES" ), aGuiObj->entry() );
HYDROData_SequenceOfObjects aZoneBaths = aZoneObj->GetBathymetries();
HYDROData_SequenceOfObjects::Iterator aBathsIter( aZoneBaths );
Handle(HYDROData_Bathymetry) aRefBath =
Handle(HYDROData_Bathymetry)::DownCast( aBathsIter.Value() );
if( !aRefBath.IsNull() && !aRefBath->IsRemoved() )
- createObject( aBathsSect, aRefBath, aGuiObj->entry() );
+ createObject( aBathsSect, aRefBath, aGuiObj->entry(), false );
+ }
+ }
+ else if ( anObjectKind == KIND_CALCULATION )
+ {
+ Handle(HYDROData_Calculation) aCaseObj =
+ Handle(HYDROData_Calculation)::DownCast( aDataObj );
+
+ LightApp_DataObject* aPolylineSect =
+ createObject( aGuiObj, tr( "CASE_BND_POLYLINE" ), aGuiObj->entry() );
+
+ Handle(HYDROData_Polyline) aPolyline = aCaseObj->GetBoundaryPolyline();
+ if ( !aPolyline.IsNull() && !aPolyline->IsRemoved() )
+ createObject( aPolylineSect, aPolyline, aGuiObj->entry(), false );
+
+ LightApp_DataObject* aRefZonesSect =
+ createObject( aGuiObj, tr( "CASE_REFERENCE_ZONES" ), aGuiObj->entry() );
+
+ HYDROData_SequenceOfObjects aRefZones = aCaseObj->GetZones();
+ HYDROData_SequenceOfObjects::Iterator anIter( aRefZones );
+ for ( ; anIter.More(); anIter.Next() )
+ {
+ Handle(HYDROData_Zone) aRefZone =
+ Handle(HYDROData_Zone)::DownCast( anIter.Value() );
+ if( !aRefZone.IsNull() && !aRefZone->IsRemoved() )
+ createObject( aRefZonesSect, aRefZone, aGuiObj->entry(), false );
+ }
+
+ LightApp_DataObject* aSplittedZonesSect =
+ createObject( aGuiObj, tr( "CASE_SPLITTED_ZONES" ), aGuiObj->entry() );
+
+ HYDROData_SequenceOfObjects aSplittedZones = aCaseObj->GetSplittedZones();
+ anIter.Init( aSplittedZones );
+ for ( ; anIter.More(); anIter.Next() )
+ {
+ Handle(HYDROData_Zone) aSplittedZone =
+ Handle(HYDROData_Zone)::DownCast( anIter.Value() );
+ if( !aSplittedZone.IsNull() && !aSplittedZone->IsRemoved() )
+ createObject( aSplittedZonesSect, aSplittedZone, aGuiObj->entry(), false );
}
}
}
*/
LightApp_DataObject* createObject( SUIT_DataObject* theParent,
Handle(HYDROData_Object) theModelObject,
- const QString& theParentEntry = QString() );
+ const QString& theParentEntry = QString(),
+ const bool theIsBuildTree = true );
/**
* Creates the GUI data object without corresponding model object: just by name
enum ViewManagerRole { VMR_Unknown = 0, VMR_General,
VMR_TransformImage, VMR_ObserveImage,
- VMR_PreviewZone };
+ VMR_PreviewZone, VMR_PreviewCaseZones };
typedef QPair< SUIT_ViewManager*, ViewManagerRole > ViewManagerInfo;
typedef QMap < int, ViewManagerInfo > ViewManagerMap;
#include <HYDROData_Zone.h>
+void printPath( const QString& thePrefix, const QPainterPath& thePath )
+{
+ printf( "%s (n=%d) :", qPrintable( thePrefix ), thePath.elementCount() );
+ for( int i = 0, n = thePath.elementCount(); i < n; i++ )
+ {
+ const QPainterPath::Element anElement = thePath.elementAt( i );
+ switch( anElement.type )
+ {
+ case QPainterPath::MoveToElement:
+ printf( " M(%.0f,%.0f)", anElement.x, anElement.y );
+ break;
+ case QPainterPath::LineToElement:
+ printf( " L(%.0f,%.0f)", anElement.x, anElement.y );
+ break;
+ default:
+ break;
+ }
+ }
+ printf( "\n" );
+}
+
HYDROGUI_SplitZonesTool::SplitDataList
HYDROGUI_SplitZonesTool::SplitZones( const HYDROData_SequenceOfObjects& theZoneList,
const Handle(HYDROData_Polyline)& thePolylie )
const QPainterPath& aPath1 = theData1.Path;
const QPainterPath& aPath2 = theData2.Path;
+ printPath( "aPath1", aPath1 );
+ printPath( "aPath2", aPath2 );
const QStringList& aZoneNames1 = theData1.ZoneNames;
const QStringList& aZoneNames2 = theData2.ZoneNames;
QPainterPath anIntersection = aPath1.intersected( aPath2 );
+ printPath( "anIntersection", anIntersection );
+ anIntersection.closeSubpath();
+ printPath( "anIntersection after closing", anIntersection );
if( anIntersection.isEmpty() )
{
aSplitDataList.append( theData1 );
- aSplitDataList.append( theData2 );
+ //aSplitDataList.append( theData2 );
}
else
{
aSplitDataList.append( SplitData( anIntersection, aZoneNames1 + aZoneNames2 ) );
QPainterPath aPath1Sub = aPath1.subtracted( aPath2 );
+ printPath( "aPath1Sub", aPath1Sub );
if( !aPath1Sub.isEmpty() )
aSplitDataList.append( ExtractSeparateData( SplitData( aPath1Sub, aZoneNames1 ) ) );
QPainterPath aPath2Sub = aPath2.subtracted( aPath1 );
+ printPath( "aPath2Sub", aPath2Sub );
if( !aPath2Sub.isEmpty() )
aSplitDataList.append( ExtractSeparateData( SplitData( aPath2Sub, aZoneNames2 ) ) );
}
const QPainterPath& aPath2 = aPathList.last();
if( aPath1.contains( aPath2 ) || aPath2.contains( aPath1 ) )
{
+ printf( "HOLE CASE!\n" );
aSplitDataList.append( theData );
return aSplitDataList;
}
while( anIter.hasNext() )
{
const QPainterPath& aPath = anIter.next();
+ printPath( "aPath", aPath );
aSplitDataList.append( SplitData( aPath, aBaseZoneNames ) );
}
return aSplitDataList;
QPainterPath Path;
QStringList ZoneNames;
+ SplitData() {}
+
SplitData( const QPainterPath& thePath,
const QStringList& theZoneNames ) :
Path( thePath ), ZoneNames( theZoneNames ) {}
#include <HYDROData_Document.h>
#include <HYDROData_Iterator.h>
+#include <HYDROData_Zone.h>
#include <GraphicsView_Viewer.h>
}
Handle(HYDROData_Object) HYDROGUI_Tool::FindObjectByName( HYDROGUI_Module* theModule,
- const QString& theName,
+ const QString& theName,
const ObjectKind theObjectKind )
{
Handle(HYDROData_Object) anObject;
+ if ( theName.isEmpty() )
+ return anObject;
+
+ QStringList aNamesList;
+ aNamesList << theName;
+
+ HYDROData_SequenceOfObjects aSeqOfObjs = FindObjectsByNames( theModule, aNamesList, theObjectKind );
+ if( aSeqOfObjs.IsEmpty() )
+ return anObject;
+
+ anObject = aSeqOfObjs.First();
+ return anObject;
+}
+
+HYDROData_SequenceOfObjects HYDROGUI_Tool::FindObjectsByNames( HYDROGUI_Module* theModule,
+ const QStringList& theNames,
+ const ObjectKind theObjectKind )
+{
+ HYDROData_SequenceOfObjects aResSeq;
+ if ( theNames.isEmpty() )
+ return aResSeq;
Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( theModule->getStudyId() );
if( aDocument.IsNull() )
- return anObject;
+ return aResSeq;
+
+ QStringList aNamesList = theNames;
HYDROData_Iterator anIter( aDocument, theObjectKind );
for( ; anIter.More(); anIter.Next() )
{
Handle(HYDROData_Object) anObjectRef = anIter.Current();
- if( !anObjectRef.IsNull() && anObjectRef->GetName() == theName )
- {
- anObject = anObjectRef;
+ if( anObjectRef.IsNull() )
+ continue;
+
+ QString anObjName = anObjectRef->GetName();
+ if ( anObjName.isEmpty() || !aNamesList.contains( anObjName ) )
+ continue;
+
+ aResSeq.Append( anObjectRef );
+
+ aNamesList.removeAll( anObjName );
+ if ( aNamesList.isEmpty() )
break;
- }
}
- return anObject;
+
+ return aResSeq;
}
-QString HYDROGUI_Tool::GenerateObjectName( HYDROGUI_Module* theModule,
- const QString& thePrefix )
+QString HYDROGUI_Tool::GenerateObjectName( HYDROGUI_Module* theModule,
+ const QString& thePrefix,
+ const QStringList& theUsedNames )
{
QString aName;
int anId = 1;
{
aName = QString( "%1_%2" ).arg( thePrefix ).arg( QString::number( anId++ ) );
+ if ( theUsedNames.contains( aName ) )
+ continue;
+
// check that there are no other objects with the same name in the document
Handle(HYDROData_Object) anObject = FindObjectByName( theModule, aName, KIND_UNKNOWN );
if( anObject.IsNull() )
}
return dock;
}
+
+QColor HYDROGUI_Tool::GenerateFillingColor( HYDROGUI_Module* theModule,
+ const QStringList& theZoneNames )
+{
+ QColor aFillingColor( HYDROData_Zone::DefaultFillingColor() );
+
+ int aCounter = 0;
+ int aR = 0, aG = 0, aB = 0;
+ QStringListIterator aZoneNameIter( theZoneNames );
+ while( aZoneNameIter.hasNext() )
+ {
+ const QString& aZoneName = aZoneNameIter.next();
+ Handle(HYDROData_Zone) aRefZone = Handle(HYDROData_Zone)::DownCast(
+ FindObjectByName( theModule, aZoneName, KIND_ZONE ) );
+ if( !aRefZone.IsNull() )
+ {
+ QColor aRefColor = aRefZone->GetFillingColor();
+ aR += aRefColor.red();
+ aG += aRefColor.green();
+ aB += aRefColor.blue();
+ aCounter++;
+ }
+ }
+
+ if( aCounter > 0 )
+ {
+ aFillingColor = QColor( aR / aCounter, aG / aCounter, aB / aCounter );
+ }
+
+ return aFillingColor;
+}
+
const QString& theName,
const ObjectKind theObjectKind = KIND_UNKNOWN );
+ /**
+ * \brief Find the data objects with the specified names.
+ * \param theModule module
+ * \param theNames list of names
+ * \param theObjectKind kind of object
+ * \return list of data objects
+ */
+ static HYDROData_SequenceOfObjects FindObjectsByNames( HYDROGUI_Module* theModule,
+ const QStringList& theNames,
+ const ObjectKind theObjectKind = KIND_UNKNOWN );
+
/**
* \brief Generate name for new object.
* \param theModule module
* \param thePrefix name prefix
+ * \param theUsedNames list of already used names
* \return generated name
*/
- static QString GenerateObjectName( HYDROGUI_Module* theModule,
- const QString& thePrefix );
+ static QString GenerateObjectName( HYDROGUI_Module* theModule,
+ const QString& thePrefix,
+ const QStringList& theUsedNames = QStringList() );
/**
* \brief Get id of the active GraphicsView view.
*/
static QDockWidget* WindowDock( QWidget* wid );
+ /**
+ * \brief Generates the filling color for intersected zone
+ * \param theModule module
+ * \param theZoneNames list of intersected zones
+ * \return result color
+ */
+ static QColor GenerateFillingColor( HYDROGUI_Module* theModule,
+ const QStringList& theZoneNames );
+
};
#endif
<source>BATHYMETRY_FILTER</source>
<translation>Bathymetry files (*.xyz);;All files (*.* *)</translation>
</message>
+ <message>
+ <source>CASE_BND_POLYLINE</source>
+ <translation>Boundary polyline</translation>
+ </message>
+ <message>
+ <source>CASE_REFERENCE_ZONES</source>
+ <translation>Reference zones</translation>
+ </message>
+ <message>
+ <source>CASE_SPLITTED_ZONES</source>
+ <translation>Splitted zones</translation>
+ </message>
<message>
<source>FILE_NOT_EXISTS_OR_CANT_BE_READ</source>
<translation>The file '%1'
<source>CALCULATION_NAME</source>
<translation>Calculation case name</translation>
</message>
+ <message>
+ <source>CALCULATION_REFERENCE_ZONES</source>
+ <translation>Reference zones</translation>
+ </message>
+ <message>
+ <source>CALCULATION_SPLITTED_ZONES</source>
+ <translation>Splitted zones</translation>
+ </message>
+ <message>
+ <source>PREFIX_SPLITTED_ZONES</source>
+ <translation>Prefix of splitted zones</translation>
+ </message>
+ <message>
+ <source>CALCULATION_ZONES</source>
+ <translation>Case zones</translation>
+ </message>
+ <message>
+ <source>DEFAULT_PREFIX_SPLITTED_ZONES</source>
+ <translation>Splitt</translation>
+ </message>
<message>
<source>NAME</source>
<translation>Name</translation>
</message>
+ <message>
+ <source>SPLIT_REFERENCE_ZONES</source>
+ <translation>Split zones</translation>
+ </message>
</context>
<context>
<source>EDIT_CALCULATION</source>
<translation>Edit calculation case</translation>
</message>
+ <message>
+ <source>PREVIEW_CASE_ZONES</source>
+ <translation>Preview case zones</translation>
+ </message>
</context>
<context>