#include <BRepAlgoAPI_Fuse.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
#include <GCPnts_QuasiUniformDeflection.hxx>
-#include <NCollection_IndexedMap.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Compound.hxx>
#include <TopoDS_Edge.hxx>
IMPLEMENT_STANDARD_HANDLE(HYDROData_LandCoverMap, HYDROData_Entity)
IMPLEMENT_STANDARD_RTTIEXT(HYDROData_LandCoverMap, HYDROData_Entity)
-class HYDROData_MapOfFaceToStricklerType : public NCollection_IndexedDataMap<TopoDS_Face, QString>
-{
-};
-
/**
Constructor
@param theMap the land cover map to iterate through
#include <HYDROData_Entity.h>
#include <TDataStd_ExtStringArray.hxx>
+#include <NCollection_IndexedDataMap.hxx>
+#include <QString>
+#include <TopoDS_Face.hxx>
+
+typedef NCollection_IndexedDataMap<TopoDS_Face, QString> HYDROData_MapOfFaceToStricklerType;
DEFINE_STANDARD_HANDLE( HYDROData_LandCoverMap, HYDROData_Entity )
-class TopoDS_Face;
class TopoDS_Shape;
class TopoDS_Iterator;
class TopTools_ListOfShape;
class Handle( HYDROData_PolylineXY );
class Handle( HYDROData_Object );
-class HYDROData_MapOfFaceToStricklerType;
class gp_Pnt2d;
class HYDROData_LandCoverMap : public HYDROData_Entity
HYDRODATA_EXPORT int GetLCCount() const;
HYDRODATA_EXPORT bool IsEmpty() const;
+ HYDRODATA_EXPORT void StoreLandCovers( const HYDROData_MapOfFaceToStricklerType& );
+
protected:
void SetShape( const TopoDS_Shape& );
bool LocalPartition( const TopoDS_Shape&, const QString& theNewType );
static TopoDS_Shape MergeFaces(const TopTools_ListOfShape& theFaces,
bool IsToUnify, double theTolerance = 1E-3 );
- void StoreLandCovers( const HYDROData_MapOfFaceToStricklerType& );
public:
DEFINE_STANDARD_RTTI( HYDROData_LandCoverMap );
#include <SUIT_ResourceMgr.h>
#include <SUIT_Session.h>
#include <SUIT_FileDlg.h>
-
+#include <HYDROGUI_Module.h>
+#include <SUIT_MessageBox.h>
+#include <LightApp_Application.h>
#include <QTableWidget>
#include <QHeaderView>
#include <QComboBox>
+#include <QStackedWidget>
HYDROGUI_ImportLandCoverMapDlg::HYDROGUI_ImportLandCoverMapDlg( HYDROGUI_Module* theModule, const QString& theTitle )
: HYDROGUI_Wizard( theModule, theTitle )
addPage( createPage1() );
addPage( createPage2() );
addPage( createPage3() );
+ myFirstPageState = false;
}
QWizardPage* HYDROGUI_ImportLandCoverMapDlg::createPage1() {
myDBFAttr->addItems( theAttrNames );
}
-void HYDROGUI_ImportLandCoverMapDlg::removePolygonNames( const QStringList& theNames )
+/*void HYDROGUI_ImportLandCoverMapDlg::removePolygonNames( const QStringList& theNames )
{
QList<QListWidgetItem*> aFoundItems;
delete anItem;
}
}
-}
+}*/
void HYDROGUI_ImportLandCoverMapDlg::setSelectedPolygonNames( const QStringList& theNames )
{
{
return myDBFAttr->selectedItems().first()->text();
}
+
+void HYDROGUI_ImportLandCoverMapDlg::setFirstPageState(bool bState)
+{
+ myFirstPageState = bState;
+}
+
+bool HYDROGUI_ImportLandCoverMapDlg::acceptCurrent() const
+{
+ //Check the state of curent page
+ int CurrPage = wizard()->currentIndex();
+ switch ( CurrPage )
+ {
+ case 0:
+ {
+ if (!myFirstPageState)
+ return false;
+ break;
+ }
+ case 1:
+ {
+ if (this->myDBFAttr->selectedItems().empty())
+ return false;
+ break;
+ }
+ default:
+ return false;
+ }
+ return true;
+
+}
+
+void HYDROGUI_ImportLandCoverMapDlg::GetAttribute2StricklerCorr(QStringList& AttrValues, QStringList& ST)
+{
+ int aRowCount = myTableW->rowCount();
+ for (int i = 0; i < aRowCount; i++)
+ {
+ QTableWidgetItem* aTWI = myTableW->item(i, 0);
+ AttrValues.push_back(aTWI->text());
+ }
+
+ for (int i = 0; i < aRowCount; i++)
+ {
+ QWidget* aW = myTableW->cellWidget(i, 1);
+ QComboBox* aCB = dynamic_cast<QComboBox*> (aW);
+ ST.push_back(aCB->currentText());
+ }
+}
+
+
+QVector<int> HYDROGUI_ImportLandCoverMapDlg::getSelectedPolygonIndices() const
+{
+ QVector<int> aSelectedIndices;
+
+ QModelIndexList aSelectedItems = myPolygons->selectionModel()->selectedIndexes();
+ foreach( QModelIndex index, aSelectedItems ) {
+ aSelectedIndices << index.row();
+ }
+
+ return aSelectedIndices;
+}
\ No newline at end of file
#define HYDROGUI_ImportLandCoverMapDlg_H
#include "HYDROGUI_Wizard.h"
+#include <qvector.h>
class QListWidget;
class QLineEdit;
class QLabel;
class QTableWidget;
+
class HYDROGUI_ImportLandCoverMapDlg : public HYDROGUI_Wizard
{
Q_OBJECT
HYDROGUI_ImportLandCoverMapDlg( HYDROGUI_Module* theModule, const QString& theTitle );
virtual ~HYDROGUI_ImportLandCoverMapDlg();
- void reset();
+ void reset();
+
+ void setPolygonNames( const QStringList& theNames );
+ //void removePolygonNames( const QStringList& theNames );
- void setPolygonNames( const QStringList& theNames );
- void removePolygonNames( const QStringList& theNames );
+ void setSelectedPolygonNames( const QStringList& theNames );
- void setSelectedPolygonNames( const QStringList& theNames );
+ void setAttributeNames( const QStringList& theAttrNames );
- void setAttributeNames( const QStringList& theAttrNames );
+ void FillCorrTable(const QStringList& theFirstColumn, const QStringList& theSecondColumn);
- void FillCorrTable(const QStringList& theFirstColumn, const QStringList& theSecondColumn);
+ QStringList getSelectedPolygonNames() const;
+ QString getSelectedFieldName() const;
- QStringList getSelectedPolygonNames() const;
- QString getSelectedFieldName() const;
+ void setObjectName( const QString& theName );
+ QString getObjectName() const;
- void setObjectName( const QString& theName );
- QString getObjectName() const;
+ void setFileName( const QString& theFileName );
+ QString getFileName() const;
- void setFileName( const QString& theFileName );
- QString getFileName() const;
+ void setFirstPageState(bool bState);
+ //void setThirdPageState(bool bState);
+ void GetAttribute2StricklerCorr(QStringList& AttrValues, QStringList& ST);
+ QVector<int> getSelectedPolygonIndices() const;
signals:
- void FileSelected( const QString& theFileName );
+ void FileSelected( const QString& theFileName );
+ void selectionChanged( const QStringList& );
protected slots:
- void onBrowse();
-
-
-signals:
- void selectionChanged( const QStringList& );
+ void onBrowse();
+ void onItemSelectionChanged();
-public slots:
- void onItemSelectionChanged();
+protected:
+ bool acceptCurrent() const;
private:
- QWizardPage* createPage1();
- QWizardPage* createPage2();
- QWizardPage* createPage3();
+ QWizardPage* createPage1();
+ QWizardPage* createPage2();
+ QWizardPage* createPage3();
- QLineEdit* myFileName;
- QGroupBox* myFileNameGroup;
- QListWidget* myPolygons;
+ //First page
+ QLineEdit* myFileName;
+ QGroupBox* myFileNameGroup;
+ QListWidget* myPolygons;
- QGroupBox* myObjectNameGroup;
- QLineEdit* myObjectName;
+ QGroupBox* myObjectNameGroup;
+ QLineEdit* myObjectName;
//second page
- QGroupBox* myAttrNameGroup;
- QListWidget* myDBFAttr;
- QGroupBox* myCorrNameGroup;
+ QGroupBox* myAttrNameGroup;
+ QListWidget* myDBFAttr;
+ QGroupBox* myCorrNameGroup;
//third page
- QLabel* myCLabel;
- QTableWidget* myTableW;
+ QLabel* myCLabel;
+ QTableWidget* myTableW;
+ //State of pages
+ bool myFirstPageState;
+ //bool myThirdPageState;
};
#include <TopoDS.hxx>
#include <TopoDS_Shape.hxx>
#include <TopoDS_Wire.hxx>
-#include <qset.h>
+#include <QSet>
+
+#include <HYDROData_LandCoverMap.h>
+
+
+//TODO deny to create null-LCM (selected poltgons on the first page = 0)
+//TODO erase onBack/onFinish if not needed...
HYDROGUI_ImportLandCoverMapOp::HYDROGUI_ImportLandCoverMapOp( HYDROGUI_Module* theModule )
: HYDROGUI_Operation( theModule )
HYDROGUI_ImportLandCoverMapOp::~HYDROGUI_ImportLandCoverMapOp()
{
erasePreview();
+ myImporter.Free();
+ myAttrV.clear();
}
void HYDROGUI_ImportLandCoverMapOp::startOperation()
module()->getApp()->getViewManager( OCCViewer_Viewer::Type(), true ) ) );
}
- if ( !isApplyAndClose() ) {
- return;
- }
-
HYDROGUI_ImportLandCoverMapDlg* aPanel =
::qobject_cast<HYDROGUI_ImportLandCoverMapDlg*>( inputPanel() );
if ( !aPanel ) {
}
//
QApplication::restoreOverrideCursor();
- commitDocOperation();
+ aPanel->setFirstPageState(true);
}
else
{
commitDocOperation();
myImporter.Free();
//abort();
+ aPanel->setFirstPageState(false);
}
}
QString& theErrorMsg,
QStringList& theBrowseObjectsEntries )
{
-
+ //TODO rewrite this!
HYDROGUI_ImportLandCoverMapDlg* aPanel = ::qobject_cast<HYDROGUI_ImportLandCoverMapDlg*>( inputPanel() );
if ( !aPanel ) {
return false;
}
-
- QStringList aSelectedtPolygons = aPanel->getSelectedPolygonNames();
- aPanel->removePolygonNames( aSelectedtPolygons );
+
+ Handle(HYDROData_LandCoverMap) aLCM = Handle(HYDROData_LandCoverMap)::DownCast( doc()->CreateObject( KIND_LAND_COVER_MAP ) );
+
+ HYDROData_MapOfFaceToStricklerType aMapFace2ST;
+
+ /*QStringList aSelectedPolygons = aPanel->getSelectedPolygonNames();
+ aPanel->removePolygonNames( aSelectedPolygons );
- if (!aSelectedtPolygons.empty())
+ foreach ( QString aName, aSelectedPolygons )
{
- Handle(HYDROData_LandCoverMap) aLCM = Handle(HYDROData_LandCoverMap)::DownCast( doc()->CreateObject( KIND_LAND_COVER_MAP ) );
- TopoDS_Shape aResShape;
- if (aSelectedtPolygons.size() > 1)
- {
- TopoDS_Compound cmp;
- BRep_Builder BB;
- BB.MakeCompound(cmp);
-
- foreach ( QString aName, aSelectedtPolygons ) {
- TopoDS_Shape aShape = myPolygonName2PrsShape.value( aName )->getTopoShape();
- if ( aShape.IsNull() )
- continue;
- BB.Add(cmp, aShape);
- HYDROGUI_Shape* aShapeToDelete = myPolygonName2PrsShape.take( aName );
- delete aShapeToDelete;
- }
- aResShape = cmp;
- }
- else
- {
- TopoDS_Shape aShape = myPolygonName2PrsShape.value( aSelectedtPolygons.first() )->getTopoShape();
- if ( !aShape.IsNull() )
- {
- HYDROGUI_Shape* aShapeToDelete = myPolygonName2PrsShape.take( aSelectedtPolygons.first() );
- delete aShapeToDelete;
- aResShape = aShape;
- }
- }
- if( !aLCM.IsNull() )
- {
- QString aLCName = aPanel->getObjectName() + "_polygon";
- int i = 0;
- for( ;HYDROGUI_Tool::FindObjectByName(module(), aLCName); i++)
- aLCName = aPanel->getObjectName() + "_polygon_" + QString::number(i);
- aLCM->SetName( aLCName );
- //TODO add color
- //aLCM->SetFillingColor( aLCM->DefaultFillingColor() );
- //aLCM->SetBorderColor( aLCM->DefaultBorderColor() );
-
- //aLCM->SetShape(aResShape);
- aLCM->Show();
-
- //erasePreview();
-
- module()->setIsToUpdate( aLCM );
-
- }
+ 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);
+
+ QVector<int> aSelIndices = aPanel->getSelectedPolygonIndices();
+ foreach ( int Ind, aSelIndices ) //check i-base.
+ {
+ 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);
+ aMapFace2ST.Add( TopoDS::Face( aShape ), aST ); //TODO get from tableW
+ //HYDROGUI_Shape* aShapeToDelete = myPolygonName2PrsShape.take( aName );
+ //delete aShapeToDelete;
}
-
- module()->update( UF_Model | UF_VTKViewer | UF_VTK_Forced | UF_VTK_Init );
- if ( isApplyAndClose() )
- erasePreview();
+ //
+ aLCM->StoreLandCovers(aMapFace2ST);
+ if( !aLCM.IsNull() )
+ {
+ aLCM->SetName( "temp_name" );
+ aLCM->SetColor( QColor(0,100,100) );
+ aLCM->Show();
+ module()->setIsToUpdate( aLCM );
+
+ }
+
+ module()->update( UF_Model | UF_VTKViewer | UF_VTK_Forced | UF_VTK_Init );
+
+ erasePreview();
myImporter.Free();
+ myAttrV.clear();
return true;
}
}
erasePreview();
-
+ myImporter.Free();
HYDROGUI_Operation::abortOperation();
}
-
+//TODO take "Use dbf attrs as ST.." into account
void HYDROGUI_ImportLandCoverMapOp::onNext( const int theIndex )
{
//TODO add acceptor
if (theIndex == 2)
{
- std::vector<HYDROData_ShapeFile::DBF_AttrValue> theAttrV;
+ //std::vector<HYDROData_ShapeFile::DBF_AttrValue> myAttrV;
int Ind = myFieldList.indexOf(aPanel->getSelectedFieldName());
if (Ind == -1)
- return; //TODO add acceptor here!!
- myImporter.DBF_GetAttributeList(Ind, theAttrV );
+ {
+ return;
+ }
+ //aPanel->setSecondPageState(true);
+ myAttrV.clear();
+ myImporter.DBF_GetAttributeList(Ind, myAttrV );
mySetOfAttrValues.clear();
- for (size_t i = 0; i < theAttrV.size(); i++)
+ for (size_t i = 0; i < myAttrV.size(); i++)
{
- HYDROData_ShapeFile::DBF_AttrValue aV = theAttrV[i];
+ HYDROData_ShapeFile::DBF_AttrValue aV = myAttrV[i];
mySetOfAttrValues << QString(aV.myStrVal); //take myStrVal by now..
}
{
}
+
+void HYDROGUI_ImportLandCoverMapOp::onApply()
+{
+
+ QApplication::setOverrideCursor( Qt::WaitCursor );
+ int anUpdateFlags = 0;
+ QString anErrorMsg;
+ QStringList aBrowseObjectsEntries;
+
+ bool aResult = false;
+ try
+ {
+ aResult = processApply( anUpdateFlags, anErrorMsg, aBrowseObjectsEntries );
+ }
+ catch (...)
+ {
+ aResult = false;
+ }
+
+ QApplication::restoreOverrideCursor();
+
+ if ( aResult )
+ {
+ module()->update( anUpdateFlags );
+ commit();
+ browseObjects( aBrowseObjectsEntries );
+ }
+ else
+ {
+ abort();
+ }
+}
+
virtual bool processApply( int& theUpdateFlags, QString& theErrorMsg, QStringList& theBrowseObjectsEntries );
HYDROGUI_InputPanel* createInputPanel() const;
+ virtual void onApply();
void erasePreview();
void onNext( const int theIndex );
void onBack( const int theIndex );
+
private:
QMap<QString, HYDROGUI_Shape*> myPolygonName2PrsShape;
TopTools_SequenceOfShape myPolygonFaces;
HYDROData_ShapeFile myImporter;
QString myFileName;
QStringList myFieldList;
+ std::vector<HYDROData_ShapeFile::DBF_AttrValue> myAttrV;;
};
#endif