#include <HYDROData_Iterator.h>
#include <HYDROData_Tool.h>
#include <HYDROData_InterpolatorsFactory.h>
+#include <HYDROData_StricklerTable.h>
+#include <HYDROData_LandCoverMap.h>
#include <TDataStd_Real.hxx>
#include <TDataStd_Integer.hxx>
#include <QFile>
#include <QStringList>
#include <QTextStream>
+#include <QColor>
IMPLEMENT_STANDARD_HANDLE(HYDROData_Document,MMgt_TShared)
IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Document,MMgt_TShared)
return aNames;
}
+
+QColor HYDROData_Document::GetAssociatedColor(const QString& theStricklerType,
+ const Handle(HYDROData_StricklerTable)& theTable)
+{
+ if( !theTable.IsNull() && theTable->HasType( theStricklerType ) )
+ return theTable->GetColor( theStricklerType );
+
+ HYDROData_Iterator anIt( this, KIND_STRICKLER_TABLE );
+ for( ; anIt.More(); anIt.Next() )
+ {
+ Handle(HYDROData_StricklerTable) aTable = Handle(HYDROData_StricklerTable)::DownCast( anIt.Current() );
+ if( aTable->HasType( theStricklerType ) )
+ return aTable->GetColor( theStricklerType );
+ }
+ return QColor();
+}
\ No newline at end of file
class HYDROData_InterpolatorsFactory;
class HYDROData_IProfilesInterpolator;
+class Handle(HYDROData_StricklerTable);
+class Handle(HYDROData_LandCoverMap);
class QFile;
class gp_Pnt2d;
//! Sets default strickler coefficient
HYDRODATA_EXPORT void SetDefaultStricklerCoefficient( double ) const;
+ HYDRODATA_EXPORT QColor HYDROData_Document::GetAssociatedColor(const QString& theStricklerType,
+ const Handle(HYDROData_StricklerTable)& theTable);
+
protected:
friend class HYDROData_Iterator;
friend class test_HYDROData_Document;
#include <QHeaderView>
#include <QComboBox>
#include <QStackedWidget>
+#include <SUIT_MessageBox.h>
+#include <SUIT_Desktop.h>
+#include <QSignalMapper>
HYDROGUI_ImportLandCoverMapDlg::HYDROGUI_ImportLandCoverMapDlg( HYDROGUI_Module* theModule, const QString& theTitle )
: HYDROGUI_Wizard( theModule, theTitle )
aFileNameLayout->addWidget( aFileNameLabel );
aFileNameLayout->addWidget( myFileName );
aFileNameLayout->addWidget( aBrowseBtn );
-
+
myObjectNameGroup = new QGroupBox( tr( "LANDCOVERMAP_NAME" ) );
QLabel* aLandcoverNameLabel = new QLabel( tr( "NAME" ), myObjectNameGroup );
aPolygonsLayout->addWidget( myPolygons );
aPolygonsGroup->setLayout( aPolygonsLayout );
- // Layout
QVBoxLayout* aPageLayout = new QVBoxLayout;
+ myAttrCheckBox = new QCheckBox( "Use dBase attributes as a Strickler Types" ); //TODO replace with tr()
+ myAttrCheckBox->setChecked(true);
+
+ // Layout
aPageLayout->setMargin( 5 );
aPageLayout->setSpacing( 5 );
aPageLayout->addWidget( myFileNameGroup );
+ aPageLayout->addWidget( myAttrCheckBox );
aPageLayout->addWidget( myObjectNameGroup );
aPageLayout->addWidget( aPolygonsGroup );
aPage->setLayout( aPageLayout );
// Conections
connect( myPolygons, SIGNAL( itemSelectionChanged() ), this, SLOT( onItemSelectionChanged() ) );
connect( aBrowseBtn, SIGNAL( clicked() ), this, SLOT( onBrowse() ) );
+ connect( myAttrCheckBox, SIGNAL(clicked(bool)), this, SLOT(onAttrCBChecked(bool)));
return aPage;
}
QWizardPage* aPage = new QWizardPage( mainFrame() );
QFrame* aFrame = new QFrame( aPage );
- myAttrNameGroup = new QGroupBox( "Available attributes" );
-
- QCheckBox* anAttrCheckBox = new QCheckBox( "Use dBase attributes as a Strickler Types", myAttrNameGroup );
-
- QBoxLayout* aFileNameLayout = new QHBoxLayout( myAttrNameGroup );
- aFileNameLayout->setMargin( 5 );
- aFileNameLayout->setSpacing( 5 );
- aFileNameLayout->addWidget( anAttrCheckBox );
-
-
- myDBFAttr = new QListWidget( aPage );
+ myAvAttrLabel = new QLabel();
+ myAvAttrLabel->setText("Available attributes");
+
+ myDBFAttr = new QListWidget( );
myDBFAttr->setSelectionMode( QListWidget::SingleSelection );
myDBFAttr->setEditTriggers( QListWidget::NoEditTriggers );
myDBFAttr->setViewMode( QListWidget::ListMode );
QVBoxLayout* aPageLayout = new QVBoxLayout;
aPageLayout->setMargin( 5 );
aPageLayout->setSpacing( 5 );
- aPageLayout->addWidget( myAttrNameGroup );
+ aPageLayout->addWidget( myAvAttrLabel );
aPageLayout->addWidget( myDBFAttr );
aPage->setLayout( aPageLayout );
+
return aPage;
}
}
-void HYDROGUI_ImportLandCoverMapDlg::FillCorrTable(const QStringList& theFirstColumn, const QStringList& theSecondColumn)
+void HYDROGUI_ImportLandCoverMapDlg::FillCorrTable(const QStringList& theFirstColumn,
+ const QStringList& theSecondColumn,
+ const QVector<QColor> theColors)
{
int FCSize = theFirstColumn.size();
int SCSize = theSecondColumn.size();
-
- myTableW->setRowCount(FCSize);
- myTableW->setColumnCount(2);
+ myStrColors = theColors;
+
+ myTableW->setRowCount(FCSize);
+ myTableW->setColumnCount(3);
+ QTableWidgetItem* Header_1 = new QTableWidgetItem(QString("Attribute"), QTableWidgetItem::Type);
+ QTableWidgetItem* Header_2 = new QTableWidgetItem(QString("Strickler Type"), QTableWidgetItem::Type);
+ QTableWidgetItem* Header_3 = new QTableWidgetItem(QString("Color"), QTableWidgetItem::Type);
+ myTableW->setHorizontalHeaderItem(0, Header_1);
+ myTableW->setHorizontalHeaderItem(1, Header_2);
+ myTableW->setHorizontalHeaderItem(2, Header_3);
+ //
for (int i = 0; i < FCSize; i++)
{
QTableWidgetItem* aTWI = new QTableWidgetItem();
aTWI->setFlags(Qt::ItemIsUserCheckable);
myTableW->setItem(i, 0, aTWI);
}
-
+ //
+ QSignalMapper* signalMap = new QSignalMapper();
for (int i = 0; i < FCSize; i++)
{
QComboBox* aCB = new QComboBox();
+ connect(aCB, SIGNAL(currentIndexChanged(int)), signalMap, SLOT(map()));
+ signalMap->setMapping(aCB, i);
aCB->addItems(theSecondColumn);
myTableW->setCellWidget(i, 1, aCB);
}
+ connect(signalMap, SIGNAL(mapped(int)), this, SLOT(OnComboBoxColorChanged(int)));
+ //
+ for (int i = 0; i < FCSize; i++)
+ {
+ myTableW->setItem(i, 2, new QTableWidgetItem);
+ //take the first color from array; this color corresponds to the first item in the combo box
+ myTableW->item(i, 2)->setBackground(myStrColors[0]);
+ }
+
}
QString HYDROGUI_ImportLandCoverMapDlg::getSelectedFieldName() const
case 0:
{
if (!myFirstPageState)
+ {
+ SUIT_MessageBox::warning( module()->getApp()->desktop(), tr( "LCM_IMPORT_WARNING" ), "File isn't chosen");
+ return false;
+ }
+ if (myPolygons->selectedItems().empty())
+ {
+ SUIT_MessageBox::warning( module()->getApp()->desktop(), tr( "LCM_IMPORT_WARNING" ), "Polygons isn't selected");
return false;
+ }
break;
}
case 1:
{
- if (this->myDBFAttr->selectedItems().empty())
+ if (myDBFAttr->selectedItems().empty())
return false;
break;
}
}
return aSelectedIndices;
+}
+
+void HYDROGUI_ImportLandCoverMapDlg::onAttrCBChecked( bool theState )
+{
+ if (theState)
+ SetButtonsState ( false );
+ else
+ SetButtonsState ( true );
+}
+
+bool HYDROGUI_ImportLandCoverMapDlg::getAttrCheckBoxState() const
+{
+ return myAttrCheckBox->isChecked();
+}
+
+void HYDROGUI_ImportLandCoverMapDlg::OnComboBoxColorChanged(int theInd)
+{
+ QComboBox* CB = qobject_cast<QComboBox *> (myTableW->cellWidget(theInd, 1));
+ int CurIndOfCB = CB->currentIndex();
+ myTableW->item(theInd, 2)->setBackground(myStrColors[CurIndOfCB]);
}
\ No newline at end of file
class QComboBox;
class QLabel;
class QTableWidget;
+class QCheckBox;
class HYDROGUI_ImportLandCoverMapDlg : public HYDROGUI_Wizard
void setAttributeNames( const QStringList& theAttrNames );
- void FillCorrTable(const QStringList& theFirstColumn, const QStringList& theSecondColumn);
+ void FillCorrTable(const QStringList& theFirstColumn,
+ const QStringList& theSecondColumn,
+ const QVector<QColor> theColors);
QStringList getSelectedPolygonNames() const;
QString getSelectedFieldName() const;
QString getFileName() const;
void setFirstPageState(bool bState);
- //void setThirdPageState(bool bState);
+ bool getAttrCheckBoxState() const;
void GetAttribute2StricklerCorr(QStringList& AttrValues, QStringList& ST);
QVector<int> getSelectedPolygonIndices() const;
protected slots:
void onBrowse();
void onItemSelectionChanged();
+ void onAttrCBChecked(bool theState);
+ void OnComboBoxColorChanged(int theInd);
protected:
bool acceptCurrent() const;
QLineEdit* myFileName;
QGroupBox* myFileNameGroup;
QListWidget* myPolygons;
-
QGroupBox* myObjectNameGroup;
QLineEdit* myObjectName;
+ QCheckBox* myAttrCheckBox;
- //second page
- QGroupBox* myAttrNameGroup;
+ //Second page
QListWidget* myDBFAttr;
- QGroupBox* myCorrNameGroup;
+ QLabel* myAvAttrLabel;
- //third page
+ //Third page
QLabel* myCLabel;
QTableWidget* myTableW;
- //State of pages
+ //State of the first page
bool myFirstPageState;
- //bool myThirdPageState;
+ QVector<QColor> myStrColors;
};
#endif
#include <HYDROData_LandCoverMap.h>
-
-//TODO deny to create null-LCM (selected poltgons on the first page = 0)
-//TODO erase onBack/onFinish if not needed...
-
+//TODO add definitions into TS file
HYDROGUI_ImportLandCoverMapOp::HYDROGUI_ImportLandCoverMapOp( HYDROGUI_Module* theModule )
: HYDROGUI_Operation( theModule )
{
HYDROGUI_InputPanel* aPanel = new HYDROGUI_ImportLandCoverMapDlg( module(), getName() );
connect( aPanel, SIGNAL( FileSelected( const QString& ) ), SLOT( onFileSelected() ) );
-
connect( aPanel, SIGNAL( selectionChanged( const QStringList& ) ), this, SLOT( onSelectionChanged( const QStringList& ) ) );
-
connect( aPanel, SIGNAL( Next( const int ) ), SLOT( onNext( const int ) ) );
- connect( aPanel, SIGNAL( Back( const int ) ), SLOT( onBack( const int ) ) );
- connect( aPanel, SIGNAL( Finish( const int ) ), SLOT( onFinish( const int ) ) );
return aPanel;
}
QString& theErrorMsg,
QStringList& theBrowseObjectsEntries )
{
- //TODO rewrite this!
+
HYDROGUI_ImportLandCoverMapDlg* aPanel = ::qobject_cast<HYDROGUI_ImportLandCoverMapDlg*>( inputPanel() );
if ( !aPanel ) {
return false;
}
Handle(HYDROData_LandCoverMap) aLCM = Handle(HYDROData_LandCoverMap)::DownCast( doc()->CreateObject( KIND_LAND_COVER_MAP ) );
-
HYDROData_MapOfFaceToStricklerType aMapFace2ST;
- /*QStringList aSelectedPolygons = aPanel->getSelectedPolygonNames();
- aPanel->removePolygonNames( aSelectedPolygons );
-
- foreach ( QString aName, aSelectedPolygons )
- {
- TopoDS_Shape aShape = myPolygonName2PrsShape.value( aName )->getTopoShape();
- if ( aShape.IsNull() )
- continue;
- aMapFace2ST.Add( TopoDS::Face( aShape ), "TODO temp" ); //TODO get from tableW
- HYDROGUI_Shape* aShapeToDelete = myPolygonName2PrsShape.take( aName );
- delete aShapeToDelete;
- }*/
QStringList aAttrV_T;
QStringList aSTL;
aPanel->GetAttribute2StricklerCorr(aAttrV_T, aSTL);
TopoDS_Shape aShape = myPolygonFaces(Ind + 1);
if ( aShape.IsNull() )
continue;
- HYDROData_ShapeFile::DBF_AttrValue aV = myAttrV[Ind];
- int StricklerTypesInd = aAttrV_T.indexOf(QString(aV.myStrVal));
- QString aST = aSTL.at(StricklerTypesInd);
+ QString aST = "";
+ if (aPanel->getAttrCheckBoxState())
+ {
+ HYDROData_ShapeFile::DBF_AttrValue aV = myAttrV[Ind];
+ int StricklerTypesInd = aAttrV_T.indexOf(QString(aV.myStrVal));
+ aST = aSTL.at(StricklerTypesInd);
+ }
+ // else => ST is empty
aMapFace2ST.Add( TopoDS::Face( aShape ), aST ); //TODO get from tableW
- //HYDROGUI_Shape* aShapeToDelete = myPolygonName2PrsShape.take( aName );
- //delete aShapeToDelete;
}
//
aLCM->StoreLandCovers(aMapFace2ST);
+ QString ObjName;
+ if ( !aPanel->getFileName().isEmpty() )
+ ObjName = aPanel->getObjectName();
+
if( !aLCM.IsNull() )
{
- aLCM->SetName( "temp_name" );
- aLCM->SetColor( QColor(0,100,100) );
+ aLCM->SetName( ObjName );
+ aLCM->SetColor( Qt::gray );
aLCM->Show();
module()->setIsToUpdate( aLCM );
-
}
module()->update( UF_Model | UF_VTKViewer | UF_VTK_Forced | UF_VTK_Init );
bool isSelected = theSelectedNames.contains( aName );
if ( ( isSelected && !aCtx->IsSelected( anObject) ) ||
- ( !isSelected && aCtx->IsSelected( anObject) ) ) {
+ ( !isSelected && aCtx->IsSelected( anObject) ) )
aCtx->AddOrRemoveSelected( anObject, Standard_False );
- }
- /*if (isSelected)
- {
- HYDROGUI_Shape* aHydroSh = myPolygonName2PrsShape.value( aName );
- aHydroSh->setFillingColor(QColor(0,255,255), true, true);
- }*/
}
aCtx->UpdateCurrentViewer();
}
void HYDROGUI_ImportLandCoverMapOp::onViewerSelectionChanged()
{
- // Get panel
HYDROGUI_ImportLandCoverMapDlg* aPanel = ::qobject_cast<HYDROGUI_ImportLandCoverMapDlg*>( inputPanel() );
if ( !aPanel ) {
return;
QStringList aSelectedNames;
foreach ( QString aName, myPolygonName2PrsShape.keys() ) {
bool isSelected = aCtx->IsSelected( myPolygonName2PrsShape.value(aName)->getAISObject() );
- if ( isSelected ) {
+ if ( isSelected )
aSelectedNames << aName;
- }
}
aPanel->setSelectedPolygonNames( aSelectedNames );
}
HYDROGUI_Operation::abortOperation();
}
-//TODO take "Use dbf attrs as ST.." into account
void HYDROGUI_ImportLandCoverMapOp::onNext( const int theIndex )
{
- //TODO add acceptor
HYDROGUI_ImportLandCoverMapDlg* aPanel = ::qobject_cast<HYDROGUI_ImportLandCoverMapDlg*>( inputPanel() );
if ( !aPanel )
return;
}
}
}
- aPanel->FillCorrTable(mySetOfAttrValues.toList(), aSTSet.toList());
+ QList<QString> SetOfAttrValuesList = mySetOfAttrValues.toList();
+ QList<QString> aSTSetList = aSTSet.toList();
+ QVector<QColor> STColors;
+ STColors.reserve(aSTSetList.size());
+ foreach (QString str, aSTSetList)
+ {
+ QColor col = aDoc->GetAssociatedColor(str, NULL);
+ STColors.append (col);
+ }
+
+ aPanel->FillCorrTable(SetOfAttrValuesList, aSTSetList, STColors);
}
}
-void HYDROGUI_ImportLandCoverMapOp::onBack( const int theIndex )
-{
-
-}
void HYDROGUI_ImportLandCoverMapOp::onApply()
{
-
QApplication::setOverrideCursor( Qt::WaitCursor );
int anUpdateFlags = 0;
QString anErrorMsg;
}
catch (...)
{
+ SUIT_MessageBox::critical( module()->getApp()->desktop(), tr( "LCM_IMPORT_ERROR" ), "Cant import choosed polygons");
aResult = false;
}
void onSelectionChanged( const QStringList& theSelectedNames );
void onViewerSelectionChanged ();
void onNext( const int theIndex );
- void onBack( const int theIndex );
-
private:
QMap<QString, HYDROGUI_Shape*> myPolygonName2PrsShape;
return Quantity_Color();
}
- if( !myTable.IsNull() && myTable->HasType( theStricklerType ) )
- {
- QColor aColor = myTable->GetColor( theStricklerType );
- return HYDROData_Tool::toOccColor( aColor );
- }
+ QColor aColor = HYDROData_Document::Document( myLCMap->Label())->GetAssociatedColor(theStricklerType, myTable);
- HYDROData_Iterator anIt( HYDROData_Document::Document( myLCMap->Label() ), KIND_STRICKLER_TABLE );
- for( ; anIt.More(); anIt.Next() )
- {
- Handle(HYDROData_StricklerTable) aTable = Handle(HYDROData_StricklerTable)::DownCast( anIt.Current() );
- if( aTable->HasType( theStricklerType ) )
- {
- QColor aColor = aTable->GetColor( theStricklerType );
- return HYDROData_Tool::toOccColor( aColor );
- }
- }
-
- return Quantity_Color();
+ if (aColor.isValid())
+ return HYDROData_Tool::toOccColor(aColor);
+ else
+ return Quantity_Color();
}
void HYDROGUI_LandCoverMapPrs::Compute( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
{
if ( myWizard->count() > 0 )
{
- myNext->setVisible( true );
- myFinish->setVisible( false );
+ SetButtonsState(false);
+ /*myNext->setVisible( true );
+ myFinish->setVisible( false );*/
}
return myWizard->addWidget( thePage );
}
myBack->setEnabled( true );
int aCurIdx = myWizard->currentIndex();
- if ( aCurIdx == ( myWizard->count() - 2 ) )
+ if ( IsLastPage() )
{
// Go to the last page
- myNext->setVisible( false );
- myFinish->setVisible( true );
+ SetButtonsState( true );
+ /*myNext->setVisible( false );
+ myFinish->setVisible( true );*/
}
myWizard->setCurrentIndex( aCurIdx + 1 );
if ( myWizard->count() > 1 )
{
- myNext->setVisible( true );
- myFinish->setVisible( false );
+ /*myNext->setVisible( true );
+ myFinish->setVisible( false );*/
+ SetButtonsState( false );
}
else
{
// Wizard has a single page - show finish
- myNext->setVisible( false );
- myFinish->setVisible( true );
+ SetButtonsState( true );
+ /*myNext->setVisible( false );
+ myFinish->setVisible( true );*/
}
int aCurIdx = myWizard->currentIndex();
void HYDROGUI_Wizard::onFirstPage()
{
if ( myWizard->count() > 1 ) {
- myNext->setVisible( true );
- myFinish->setVisible( false );
+ /*myNext->setVisible( true );
+ myFinish->setVisible( false );*/
+ SetButtonsState( false );
myWizard->setCurrentIndex( 0 );
myBack->setEnabled( false );
emit Back( myWizard->currentIndex() );
aRes = myHelp;
}
return aRes;
+}
+
+bool HYDROGUI_Wizard::IsLastPage()
+{
+ if ( myWizard->currentIndex() == ( myWizard->count() - 2 ))
+ return true;
+ else
+ return false;
+}
+
+void HYDROGUI_Wizard::SetButtonsState (bool IsLastPage)
+{
+ if (!IsLastPage)
+ {
+ myNext->setVisible( true );
+ myFinish->setVisible( false );
+ }
+ else
+ {
+ myNext->setVisible( false );
+ myFinish->setVisible( true );
+ }
}
\ No newline at end of file
// Reimplement this method in your subclass to verify user input data.
virtual bool acceptCurrent() const;
+ virtual bool IsLastPage();
+
+ void SetButtonsState (bool IsLastPage);
+
private:
QStackedWidget* myWizard;
QPushButton* myNext;