bool LocalPartition( const TopoDS_Shape&, const QString& theNewType );
static TopoDS_Shape MergeFaces(const TopTools_ListOfShape& theFaces,
- bool IsToUnify, double theTolerance = 1E-3 );
+ bool IsToUnify, double theTolerance = 1E-5 );
public:
DEFINE_STANDARD_RTTI( HYDROData_LandCoverMap );
addPage( createPage2() );
addPage( createPage3() );
myFirstPageState = false;
+ myDbfState = false;
}
QWizardPage* HYDROGUI_ImportLandCoverMapDlg::createPage1() {
HYDROGUI_ImportLandCoverMapDlg::~HYDROGUI_ImportLandCoverMapDlg()
{
+ myPolygons->clear();
+ myDBFAttr->clear();
}
void HYDROGUI_ImportLandCoverMapDlg::reset()
QStringList aSelectedNames;
QList<QListWidgetItem*> aSelectedItems = myPolygons->selectedItems();
- foreach( const QListWidgetItem* anItem, aSelectedItems ) {
+ foreach( const QListWidgetItem* anItem, aSelectedItems )
aSelectedNames << anItem->text();
- }
return aSelectedNames;
}
bool HYDROGUI_ImportLandCoverMapDlg::acceptCurrent() const
{
- //Check the state of curent page
+ //Check the state of the current page
int CurrPage = wizard()->currentIndex();
switch ( CurrPage )
{
SUIT_MessageBox::warning( module()->getApp()->desktop(), tr( "LCM_IMPORT_WARNING" ), "Polygons isn't selected");
return false;
}
+ if (getAttrCheckBoxState() && !getDbfState())
+ {
+ SUIT_MessageBox::critical( module()->getApp()->desktop(), tr( "DBF_LOAD_ERROR" ), "Cant open DBF file or it's corrupted");
+ return false;
+ }
break;
}
case 1:
return false;
}
return true;
-
}
void HYDROGUI_ImportLandCoverMapDlg::GetAttribute2StricklerCorr(QStringList& AttrValues, QStringList& ST)
void HYDROGUI_ImportLandCoverMapDlg::OnComboBoxColorChanged(int theInd)
{
- QComboBox* CB = qobject_cast<QComboBox *> (myTableW->cellWidget(theInd, 1));
+ QComboBox* CB = qobject_cast<QComboBox*> (myTableW->cellWidget(theInd, 1));
int CurIndOfCB = CB->currentIndex();
myTableW->item(theInd, 2)->setBackground(myStrColors[CurIndOfCB]);
+}
+
+void HYDROGUI_ImportLandCoverMapDlg::setDbfState(bool _state)
+{
+ myDbfState = _state;
+}
+
+bool HYDROGUI_ImportLandCoverMapDlg::getDbfState() const
+{
+ return myDbfState;
}
\ No newline at end of file
void reset();
void setPolygonNames( const QStringList& theNames );
- //void removePolygonNames( const QStringList& theNames );
-
void setSelectedPolygonNames( const QStringList& theNames );
-
void setAttributeNames( const QStringList& theAttrNames );
-
void FillCorrTable(const QStringList& theFirstColumn,
const QStringList& theSecondColumn,
const QVector<QColor> theColors);
void GetAttribute2StricklerCorr(QStringList& AttrValues, QStringList& ST);
QVector<int> getSelectedPolygonIndices() const;
+ void setDbfState(bool _state);
+ bool getDbfState() const;
+
signals:
void FileSelected( const QString& theFileName );
void selectionChanged( const QStringList& );
//State of the first page
bool myFirstPageState;
-
QVector<QColor> myStrColors;
+ bool myDbfState;
};
#endif
myPolygonName2PrsShape.insert( "polygon_" + QString::number(i), aShape);
}
}
+
if ( !aCtx.IsNull() )
{
UpdateZLayersOfHilightPresentationsOfDisplayedObjects( aCtx, Graphic3d_ZLayerId_TopOSD );
//
QApplication::restoreOverrideCursor();
aPanel->setFirstPageState(true);
+ //
+ //Try to load DBF-database...
+ QString theDBFFileName;
+ theDBFFileName = myFileName.simplified().replace( ".shp", ".dbf", Qt::CaseInsensitive);
+ bool DBF_Stat = myImporter.DBF_OpenDBF(theDBFFileName);
+ // TODO:
+ // add MSG BOX if stat is bad
+ if (DBF_Stat)
+ {
+ myFieldList = myImporter.DBF_GetFieldList();
+ aPanel->setAttributeNames(myFieldList);
+ }
+ aPanel->setDbfState(DBF_Stat);
}
else
{
aPanel->setPolygonNames(QStringList());
aPanel->setObjectName("");
QApplication::restoreOverrideCursor();
- QString aMess = "Cannot import land cover;\n";
+ QString aMess = "Cannot import content of this file as land cover map;\n";
if (aStat == -1)
aMess += "Cannot open SHP file";
else if (aStat == -2)
}
bool HYDROGUI_ImportLandCoverMapOp::processApply( int& theUpdateFlags,
- QString& theErrorMsg,
- QStringList& theBrowseObjectsEntries )
+ QString& theErrorMsg,
+ QStringList& theBrowseObjectsEntries )
{
HYDROGUI_ImportLandCoverMapDlg* aPanel = ::qobject_cast<HYDROGUI_ImportLandCoverMapDlg*>( inputPanel() );
- if ( !aPanel ) {
+ if ( !aPanel )
return false;
- }
- Handle(HYDROData_LandCoverMap) aLCM = Handle(HYDROData_LandCoverMap)::DownCast( doc()->CreateObject( KIND_LAND_COVER_MAP ) );
+ myLCM = Handle(HYDROData_LandCoverMap)::DownCast( doc()->CreateObject( KIND_LAND_COVER_MAP ) );
HYDROData_MapOfFaceToStricklerType aMapFace2ST;
QStringList aAttrV_T;
}
//
- aLCM->StoreLandCovers(aMapFace2ST);
+ myLCM->StoreLandCovers(aMapFace2ST);
QString ObjName;
if ( !aPanel->getFileName().isEmpty() )
ObjName = aPanel->getObjectName();
- if( !aLCM.IsNull() )
+ if( !myLCM.IsNull() )
{
- aLCM->SetName( ObjName );
- aLCM->SetColor( Qt::gray );
- aLCM->Show();
- module()->setIsToUpdate( aLCM );
+ myLCM->SetName( ObjName );
+ myLCM->SetColor( Qt::gray );
+ myLCM->Show();
+ module()->setIsToUpdate( myLCM );
}
module()->update( UF_Model | UF_VTKViewer | UF_VTK_Forced | UF_VTK_Init );
if ( !aPanel )
return;
- if (theIndex == 1)
- {
- //Try to load DBF-database...
- QString theDBFFileName;
- theDBFFileName = myFileName.simplified().replace( ".shp", ".dbf", Qt::CaseInsensitive);
- bool DBF_Stat = myImporter.DBF_OpenDBF(theDBFFileName);
- // TODO:
- // add MSG BOX if stat is bad
- myFieldList = myImporter.DBF_GetFieldList();
- aPanel->setAttributeNames(myFieldList);
- }
-
if (theIndex == 2)
{
//std::vector<HYDROData_ShapeFile::DBF_AttrValue> myAttrV;
int Ind = myFieldList.indexOf(aPanel->getSelectedFieldName());
if (Ind == -1)
- {
return;
- }
//aPanel->setSecondPageState(true);
myAttrV.clear();
myImporter.DBF_GetAttributeList(Ind, myAttrV );
}
else
{
+ Handle(HYDROData_Entity) LCM = Handle(HYDROData_Entity)::DownCast( myLCM );
+ LCM->Remove();
+ module()->setObjectRemoved( myLCM );
abort();
}
}
class SUIT_FileDlg;
class HYDROGUI_Shape;
class TopoDS_Face;
+//class HYDROData_LandCoverMap;
+#include <HYDROData_LandCoverMap.h>
class HYDROGUI_ImportLandCoverMapOp : public HYDROGUI_Operation
{
HYDROData_ShapeFile myImporter;
QString myFileName;
QStringList myFieldList;
- std::vector<HYDROData_ShapeFile::DBF_AttrValue> myAttrV;;
+ std::vector<HYDROData_ShapeFile::DBF_AttrValue> myAttrV;
+ Handle(HYDROData_LandCoverMap) myLCM;
};
#endif
UpdateView(theEntities);
else
{
- QString aMess = "Cannot import polyline;\n";
+ QString aMess = "Cannot import content of this file as polyline;\n";
if (aStat == -1)
aMess += "Cannot open SHP file";
else if (aStat == -2)
<< QColor(100,100,20)
<< QColor(10,100,150);
}
- return aCV[i];
+ if (i < aCV.size())
+ return aCV[i];
+ else
+ {
+ QColor TestColor = aCV[i % aCV.size()];
+ QColor NewColor((TestColor.red() + i * 41) % 256,
+ (TestColor.green() + i * 13) % 256,
+ (TestColor.blue() + i * 23) % 256);
+ return NewColor;
+ }
}
void TestViewer::show( const Handle(AIS_InteractiveObject)& theObject,
--- /dev/null
+PROJCS["RGF93_Lambert_93",GEOGCS["GCS_RGF93",DATUM["D_RGF_1993",SPHEROID["GRS_1980",6378137,298.257222101]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Lambert_Conformal_Conic"],PARAMETER["standard_parallel_1",49],PARAMETER["standard_parallel_2",44],PARAMETER["latitude_of_origin",46.5],PARAMETER["central_meridian",3],PARAMETER["false_easting",700000],PARAMETER["false_northing",6600000],UNIT["Meter",1]]
\ No newline at end of file
--- /dev/null
+PROJCS["RGF93 / Lambert-93",GEOGCS["RGF93",DATUM["Reseau_Geodesique_Francais_1993",SPHEROID["GRS 1980",6378137,298.257222101,AUTHORITY["EPSG","7019"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY["EPSG","6171"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4171"]],PROJECTION["Lambert_Conformal_Conic_2SP"],PARAMETER["standard_parallel_1",49],PARAMETER["standard_parallel_2",44],PARAMETER["latitude_of_origin",46.5],PARAMETER["central_meridian",3],PARAMETER["false_easting",700000],PARAMETER["false_northing",6600000],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["X",EAST],AXIS["Y",NORTH],AUTHORITY["EPSG","2154"]]
--- /dev/null
+GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]]
\ No newline at end of file
#include <HYDROData_PolylineXY.h>
#include <HYDROData_StricklerTable.h>
#include <HYDROData_Tool.h>
+#include <HYDROData_ShapeFile.h>
#include <HYDROGUI_LandCoverMapPrs.h>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Wire.hxx>
#include <TopoDS_Face.hxx>
+#include <TopoDS.hxx>
#include <TestViewer.h>
#include <TestShape.h>
#include <TopTools_ListOfShape.hxx>
aDoc->Close();
}
+
+void test_HYDROData_LandCoverMap::test_shp_import_cyp()
+{
+ Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
+ QString myFileName = REF_DATA_PATH + "/cyprus_natural.shp";
+ HYDROData_ShapeFile anImporter;
+ QStringList PolygonList;
+ TopTools_SequenceOfShape PolygonFaces;
+ int Type = -1;
+ int aStat = anImporter.ImportPolygons(myFileName, PolygonList, PolygonFaces, Type);
+ CPPUNIT_ASSERT(aStat == 1);
+ CPPUNIT_ASSERT_EQUAL(5, Type);
+ CPPUNIT_ASSERT_EQUAL(268, PolygonFaces.Length());
+
+ Handle(HYDROData_LandCoverMap) LCM = Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
+ HYDROData_MapOfFaceToStricklerType aMapFace2ST;
+
+ for ( int i = 1; i <= PolygonFaces.Length(); i++ )
+ {
+ TopoDS_Shape aShape = PolygonFaces(i);
+ if ( aShape.IsNull() )
+ continue;
+ aMapFace2ST.Add( TopoDS::Face( aShape ), "" );
+ }
+
+ LCM->StoreLandCovers(aMapFace2ST);
+ TestViewer::show( LCM->GetShape(), AIS_Shaded, true, "cyprus_natural_all" );
+ CPPUNIT_ASSERT_IMAGES
+ aDoc->Close();
+}
+
+void test_HYDROData_LandCoverMap::test_shp_import_clc_dec()
+{
+ Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
+ QString myFileName = REF_DATA_PATH + "/CLC_decoupe.shp";
+ HYDROData_ShapeFile anImporter;
+ QStringList PolygonList;
+ TopTools_SequenceOfShape PolygonFaces;
+ int Type = -1;
+ int aStat = anImporter.ImportPolygons(myFileName, PolygonList, PolygonFaces, Type);
+ CPPUNIT_ASSERT(aStat == 1);
+ CPPUNIT_ASSERT_EQUAL(5, Type);
+ CPPUNIT_ASSERT_EQUAL(625, PolygonFaces.Length());
+
+ Handle(HYDROData_LandCoverMap) LCM = Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
+ HYDROData_MapOfFaceToStricklerType aMapFace2ST;
+
+ for ( int i = 150; i <= 350; i++ )
+ {
+ TopoDS_Shape aShape = PolygonFaces(i);
+ if ( aShape.IsNull() )
+ continue;
+ aMapFace2ST.Add( TopoDS::Face( aShape ), "" );
+ }
+
+ LCM->StoreLandCovers(aMapFace2ST);
+ TestViewer::show( LCM->GetShape(), AIS_Shaded, true, "clc_dec_150_350" );
+ CPPUNIT_ASSERT_IMAGES
+ aDoc->Close();
+}
+
+void test_HYDROData_LandCoverMap::test_shp_import_nld_areas()
+{
+ Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
+ QString myFileName = REF_DATA_PATH + "/NLD_water_areas_dcw.shp";
+ HYDROData_ShapeFile anImporter;
+ QStringList PolygonList;
+ TopTools_SequenceOfShape PolygonFaces;
+ int Type = -1;
+ int aStat = anImporter.ImportPolygons(myFileName, PolygonList, PolygonFaces, Type);
+ CPPUNIT_ASSERT(aStat == 1);
+ CPPUNIT_ASSERT_EQUAL(5, Type);
+ CPPUNIT_ASSERT_EQUAL(127, PolygonFaces.Length());
+
+ Handle(HYDROData_LandCoverMap) LCM = Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
+ HYDROData_MapOfFaceToStricklerType aMapFace2ST;
+
+ for ( int i = 1; i <= PolygonFaces.Length(); i++ )
+ {
+ TopoDS_Shape aShape = PolygonFaces(i);
+ if ( aShape.IsNull() )
+ continue;
+ aMapFace2ST.Add( TopoDS::Face( aShape ), "" );
+ }
+
+ LCM->StoreLandCovers(aMapFace2ST);
+ TestViewer::show( LCM->GetShape(), AIS_Shaded, true, "NLD_water_areas_dcw" );
+ CPPUNIT_ASSERT_IMAGES
+ aDoc->Close();
+}
+
#endif
#include <cppunit/extensions/HelperMacros.h>
+#define SHP_TESTS
class test_HYDROData_LandCoverMap : public CppUnit::TestFixture
{
CPPUNIT_TEST( test_dump_python );
CPPUNIT_TEST( test_transparent_prs );
CPPUNIT_TEST( test_assign_to_calc_case );
+#ifdef SHP_TESTS
+ CPPUNIT_TEST( test_shp_import_cyp );
+ CPPUNIT_TEST( test_shp_import_clc_dec );
+ CPPUNIT_TEST( test_shp_import_nld_areas );
+#endif
CPPUNIT_TEST_SUITE_END();
public:
void test_dump_python();
void test_transparent_prs();
void test_assign_to_calc_case();
+ void test_shp_import_cyp();
+ void test_shp_import_clc_dec();
+ void test_shp_import_nld_areas();
};
CPPUNIT_TEST_SUITE_REGISTRATION( test_HYDROData_LandCoverMap );