// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
-#include "HYDROData_LandCoverMap.h"
-#include <TDataStd_ExtStringArray.hxx>
+#include <HYDROData_LandCoverMap.h>
+#include <HYDROData_Tool.h>
+
+#include <BOPAlgo_Builder.hxx>
+#include <BOPAlgo_PaveFiller.hxx>
+#include <BOPCol_ListOfShape.hxx>
+#include <BRep_Builder.hxx>
+#include <NCollection_IndexedMap.hxx>
+#include <TNaming_Builder.hxx>
+#include <TNaming_NamedShape.hxx>
+#include <TopoDS.hxx>
+#include <TopoDS_Compound.hxx>
#include <TopoDS_Face.hxx>
+#include <TopoDS_Iterator.hxx>
#include <TopoDS_Shell.hxx>
+
#include <QString>
IMPLEMENT_STANDARD_HANDLE(HYDROData_LandCoverMap, HYDROData_Entity)
IMPLEMENT_STANDARD_RTTIEXT(HYDROData_LandCoverMap, HYDROData_Entity)
-HYDROData_LandCoverMap::HYDROData_LandCoverMap()
+class HYDROData_MapOfShapeToStricklerType : public NCollection_IndexedDataMap<TopoDS_Shape, QString>
{
+};
+
+/**
+ Constructor
+ @param theMap the land cover map to iterate through
+*/
+HYDROData_LandCoverMap::Iterator::Iterator( const HYDROData_LandCoverMap& theMap )
+{
+ Init( theMap );
}
-HYDROData_LandCoverMap::~HYDROData_LandCoverMap()
+/**
+ Initialize the iterator
+ @param theMap the land cover map to iterate through
+*/
+void HYDROData_LandCoverMap::Iterator::Init( const HYDROData_LandCoverMap& theMap )
{
+ myIterator = new TopoDS_Iterator( theMap.GetShape() );
+ myIndex = 0;
+ theMap.myLab.FindChild( DataTag_Types ).FindAttribute( TDataStd_ExtStringArray::GetID(), myArray );
}
-int HYDROData_LandCoverMap::GetNbFaces() const
+/**
+ Destructor
+*/
+HYDROData_LandCoverMap::Iterator::~Iterator()
{
- //TODO
- return 0;
+ delete myIterator;
}
-TopoDS_Face HYDROData_LandCoverMap::GetFace( int theIndex ) const
+/**
+ Return if the iterator has more elements
+ @return if the iterator has more elements
+*/
+bool HYDROData_LandCoverMap::Iterator::More() const
{
- //TODO
- return TopoDS_Face();
+ return !myArray.IsNull() && myIterator->More();
}
-QString HYDROData_LandCoverMap::GetStricklerType( int theIndex ) const
+/**
+ Move iterator to the next element
+*/
+void HYDROData_LandCoverMap::Iterator::Next()
{
- Handle(TDataStd_ExtStringArray) aTypesArray;
- if( !myLab.FindChild( DataTag_Types ).FindAttribute( TDataStd_ExtStringArray::GetID(), aTypesArray ) )
- return "";
+ myIterator->Next();
+}
- TCollection_ExtendedString aType = aTypesArray->Value( theIndex );
- TCollection_AsciiString anAscii = aType;
- return anAscii.ToCString();
+/**
+ Get the current land cover (face)
+ @return the land cover's face
+*/
+TopoDS_Face HYDROData_LandCoverMap::Iterator::Face() const
+{
+ return TopoDS::Face( myIterator->Value() );
}
-void HYDROData_LandCoverMap::SetStricklerType( int theIndex, const QString& theType )
+/**
+ Get the current land cover's Strickler type
+ @return the land cover's Strickler type
+*/
+QString HYDROData_LandCoverMap::Iterator::StricklerType() const
{
- Handle(TDataStd_ExtStringArray) aTypesArray;
- if( !myLab.FindChild( DataTag_Types ).FindAttribute( TDataStd_ExtStringArray::GetID(), aTypesArray ) )
- return;
+ if( myArray.IsNull() || myIndex < myArray->Lower() || myIndex > myArray->Upper() )
+ return "";
+ else
+ return HYDROData_Tool::toQString( myArray->Value( myIndex ) );
+}
- std::string aType = theType.toStdString();
- aTypesArray->SetValue( theIndex, aType.c_str() );
+/**
+ Constructor
+*/
+HYDROData_LandCoverMap::HYDROData_LandCoverMap()
+{
}
+/**
+ Destructor
+*/
+HYDROData_LandCoverMap::~HYDROData_LandCoverMap()
+{
+}
+
+/**
+ Import the land cover map from QGIS
+ @param theFileName the name of file
+ @return if the import is successful
+*/
bool HYDROData_LandCoverMap::ImportQGIS( const QString& theFileName )
{
//TODO
return false;
}
+/**
+ Export the land cover map to QGIS
+ @param theFileName the name of file
+ @return if the export is successful
+*/
bool HYDROData_LandCoverMap::ExportQGIS( const QString& theFileName ) const
{
//TODO
return false;
}
+/**
+ Export the land cover map for the solver (Telemac)
+ @param theFileName the name of file
+ @return if the export is successful
+*/
bool HYDROData_LandCoverMap::ExportTelemac( const QString& theFileName ) const
{
//TODO
return false;
}
-bool HYDROData_LandCoverMap::Add( const Handle( HYDROData_Object )&, const QString& theType )
+/**
+ Add a new object as land cover
+ @param theObject the object to add as land cover
+ @param theType the Strickler type for the new land cover
+ @return if the addition is successful
+*/
+bool HYDROData_LandCoverMap::Add( const Handle( HYDROData_Object )& theObject, const QString& theType )
{
//TODO
return false;
}
-bool HYDROData_LandCoverMap::Add( const Handle( HYDROData_Polyline )&, const QString& theType )
+/**
+ Add a new polyline as land cover
+ @param thePolyline the polyline to add as land cover
+ @param theType the Strickler type for the new land cover
+ @return if the addition is successful
+*/
+bool HYDROData_LandCoverMap::Add( const Handle( HYDROData_Polyline )& thePolyline, const QString& theType )
{
//TODO
return false;
}
-bool HYDROData_LandCoverMap::Add( const TopoDS_Face&, const QString& theType )
+/**
+ Remove the given face from land cover map
+ @param theFace the face to be removed
+ @return if the removing is successful
+*/
+bool HYDROData_LandCoverMap::Remove( const TopoDS_Face& theFace )
{
//TODO
return false;
}
-bool HYDROData_LandCoverMap::Remove( int theIndex )
+/**
+ Split the land cover map by the given polyline
+ @param thePolyline the tool polyline to split the land cover map
+ @return if the removing is successful
+*/
+bool HYDROData_LandCoverMap::Split( const Handle( HYDROData_Polyline )& thePolyline )
{
//TODO
return false;
}
-bool HYDROData_LandCoverMap::Split( const Handle( HYDROData_Polyline )& )
+/**
+ Merge the given faces in the land cover
+ @param theFaces the faces to merge in the land cover map
+ @param theType the Strickler type for the merged land cover
+ @return if the merge is successful
+*/
+bool HYDROData_LandCoverMap::Merge( const TopTools_ListOfShape& theFaces, const QString& theType )
{
//TODO
return false;
}
-bool HYDROData_LandCoverMap::Merge( const QList<int>&, const QString& theType )
+/**
+ Get the shape of the land cover map
+*/
+TopoDS_Shape HYDROData_LandCoverMap::GetShape() const
{
- //TODO
- return false;
+ TDF_Label aLabel = myLab.FindChild( DataTag_Shape, false );
+ if ( !aLabel.IsNull() )
+ {
+ Handle(TNaming_NamedShape) aNamedShape;
+ if( aLabel.FindAttribute( TNaming_NamedShape::GetID(), aNamedShape ) )
+ return aNamedShape->Get();
+ }
+ return TopoDS_Shape();
}
-TopoDS_Shell HYDROData_LandCoverMap::GetShape() const
+/**
+ Set the shape of the land cover map
+ @param theShape the new shape for the land cover map
+*/
+void HYDROData_LandCoverMap::SetShape( const TopoDS_Shape& theShape )
{
- //TODO
- return TopoDS_Shell();
+ TNaming_Builder aBuilder( myLab.FindChild( DataTag_Shape ) );
+ aBuilder.Generated( theShape );
}
-void HYDROData_LandCoverMap::SetShape( const TopoDS_Shell& )
+/**
+ Perform the local partition algorithm on the land cover
+ @param theNewShape the new shape to add into the land cover
+ @param theNewType the new Strickler type for the new land cover
+ @return if the local partition is successful
+*/
+bool HYDROData_LandCoverMap::LocalPartition( const TopoDS_Shape& theNewShape, const QString& theNewType )
{
//TODO
}
+
+/**
+ Replace the set of land covers in the land cover map
+ @param theMap the map of shape (face) to Strickler type (string)
+*/
+void HYDROData_LandCoverMap::StoreLandCovers( const HYDROData_MapOfShapeToStricklerType& theMap )
+{
+ TopoDS_Compound aCompound;
+ BRep_Builder aCompoundBuilder;
+ aCompoundBuilder.MakeCompound( aCompound );
+
+ int n = theMap.Size();
+ Handle( TDataStd_ExtStringArray ) aTypes =
+ TDataStd_ExtStringArray::Set( myLab.FindChild( DataTag_Types ), 0, n-1, Standard_True );
+ HYDROData_MapOfShapeToStricklerType::Iterator aNFIt( theMap );
+ for( int i=0; aNFIt.More(); aNFIt.Next(), i++ )
+ {
+ aCompoundBuilder.Add( aCompound, aNFIt.Key() );
+ aTypes->SetValue( i, HYDROData_Tool::toExtString( aNFIt.Value() ) );
+ }
+
+ SetShape( aCompound );
+}
#define HYDROData_LANDCOVER_MAP_HeaderFile
#include <HYDROData_Entity.h>
+#include <TDataStd_ExtStringArray.hxx>
DEFINE_STANDARD_HANDLE( HYDROData_LandCoverMap, HYDROData_Entity )
class TopoDS_Face;
-class TopoDS_Shell;
+class TopoDS_Shape;
+class TopoDS_Iterator;
+class TopTools_ListOfShape;
class Handle( HYDROData_Polyline );
class Handle( HYDROData_Object );
+class HYDROData_MapOfShapeToStricklerType;
class HYDROData_LandCoverMap : public HYDROData_Entity
{
DataTag_Types,
};
+ class Iterator
+ {
+ public:
+ Iterator( const HYDROData_LandCoverMap& );
+ ~Iterator();
+
+ void Init( const HYDROData_LandCoverMap& );
+ bool More() const;
+ void Next();
+
+ TopoDS_Face Face() const;
+ QString StricklerType() const;
+
+ private:
+ TopoDS_Iterator* myIterator;
+ int myIndex;
+ Handle(TDataStd_ExtStringArray) myArray;
+ };
+
HYDROData_LandCoverMap();
~HYDROData_LandCoverMap();
- int GetNbFaces() const;
- TopoDS_Face GetFace( int theIndex ) const;
-
- QString GetStricklerType( int theIndex ) const;
- void SetStricklerType( int theIndex, const QString& theType );
-
bool ImportQGIS( const QString& theFileName );
bool ExportQGIS( const QString& theFileName ) const;
bool ExportTelemac( const QString& theFileName ) const;
bool Add( const Handle( HYDROData_Object )&, const QString& theType );
bool Add( const Handle( HYDROData_Polyline )&, const QString& theType );
- bool Remove( int theIndex );
+ bool Remove( const TopoDS_Face& );
bool Split( const Handle( HYDROData_Polyline )& );
- bool Merge( const QList<int>&, const QString& theType );
+ bool Merge( const TopTools_ListOfShape&, const QString& theType );
protected:
- TopoDS_Shell GetShape() const;
- void SetShape( const TopoDS_Shell& );
- bool Add( const TopoDS_Face&, const QString& theType );
+ TopoDS_Shape GetShape() const;
+ void SetShape( const TopoDS_Shape& );
+
+ bool LocalPartition( const TopoDS_Shape&, const QString& theNewType );
+ void StoreLandCovers( const HYDROData_MapOfShapeToStricklerType& );
public:
DEFINE_STANDARD_RTTI( HYDROData_LandCoverMap );
+
+private:
+ friend class Iterator;
};
#endif
//
#include <HYDROData_StricklerTable.h>
+#include <HYDROData_Tool.h>
#include <TDataStd_NamedData.hxx>
int aColorInt = aParts[1].toInt( 0, 16 );
QString anAttrValue = aParts.size()>2 ? aParts[2] : QString();
- TCollection_ExtendedString aTypeExt = toExtString( aType );
+ TCollection_ExtendedString aTypeExt = HYDROData_Tool::toExtString( aType );
aMap->SetReal( aTypeExt, aCoeff );
aMap->SetInteger( aTypeExt, aColorInt );
- aMap->SetString( aTypeExt, toExtString( anAttrValue ) );
+ aMap->SetString( aTypeExt, HYDROData_Tool::toExtString( anAttrValue ) );
}
i++;
}
QStringList aTypes = GetTypes();
foreach( QString aType, aTypes )
{
- TCollection_ExtendedString aTypeExt = toExtString( aType );
+ TCollection_ExtendedString aTypeExt = HYDROData_Tool::toExtString( aType );
aStream << "\"" << aType << "\" " << Get( aType, 0.0 );
QString aColor = QString::number( aMap->GetInteger( aTypeExt ), 16 ).toUpper();
aColor = QString( 6-aColor.length(), '0' ) + aColor;
- QString anAttrValue = toQString( aMap->GetString( aTypeExt ) );
+ QString anAttrValue = HYDROData_Tool::toQString( aMap->GetString( aTypeExt ) );
aStream << " " << aColor;
if( !anAttrValue.isEmpty() )
double HYDROData_StricklerTable::Get( const QString& theType, double theDefault ) const
{
Handle( TDataStd_NamedData ) aMap = Map();
- TCollection_ExtendedString aType = toExtString( theType );
+ TCollection_ExtendedString aType = HYDROData_Tool::toExtString( theType );
if( aMap->HasReal( aType ) )
return aMap->GetReal( aType );
else
void HYDROData_StricklerTable::Set( const QString& theType, double theCoefficient )
{
Handle(TDataStd_NamedData) aMap = Map();
- aMap->SetReal( toExtString( theType ), theCoefficient );
+ aMap->SetReal( HYDROData_Tool::toExtString( theType ), theCoefficient );
}
void HYDROData_StricklerTable::GetCoefficientRange( double& theMin, double& theMax ) const
if( !aMap.IsNull() )
{
for( TDataStd_DataMapIteratorOfDataMapOfStringReal it( aMap->GetRealsContainer() ); it.More(); it.Next() )
- aSeq.append( toQString( it.Key() ) );
+ aSeq.append( HYDROData_Tool::toQString( it.Key() ) );
}
aSeq.sort();
return aSeq;
{
Handle(TDataStd_NamedData) aMap = Map();
- TCollection_ExtendedString aType = toExtString( theType );
+ TCollection_ExtendedString aType = HYDROData_Tool::toExtString( theType );
return !aMap.IsNull() && aMap->HasReal( aType );
}
return aMap;
}
-TCollection_ExtendedString HYDROData_StricklerTable::toExtString( const QString& theStr ) const
-{
- TCollection_ExtendedString aRes;
- if( !theStr.isEmpty() )
- {
- Standard_ExtString extStr = new Standard_ExtCharacter[ ( theStr.length() + 1 ) * 2 ];
- memcpy( (void*)extStr, theStr.unicode(), theStr.length() * 2 );
- ((short*)extStr)[theStr.length()] = '\0';
- aRes = TCollection_ExtendedString( extStr );
- delete [] extStr;
- }
- return aRes;
-}
-
-QString HYDROData_StricklerTable::toQString( const TCollection_ExtendedString& theStr ) const
-{
- return QString( (QChar*)theStr.ToExtString(), theStr.Length() );
-}
-
QString HYDROData_StricklerTable::GetAttrName() const
{
Handle(TDataStd_AsciiString) aName;
void HYDROData_StricklerTable::SetAttrName( const QString& theAttrName ) const
{
- TDataStd_AsciiString::Set( myLab.FindChild( DataTag_AttrName ), toExtString( theAttrName ) );
+ TDataStd_AsciiString::Set( myLab.FindChild( DataTag_AttrName ), HYDROData_Tool::toExtString( theAttrName ) );
}
QString HYDROData_StricklerTable::GetAttrValue( const QString& theType ) const
{
Handle( TDataStd_NamedData ) aMap = Map();
- TCollection_ExtendedString aType = toExtString( theType );
+ TCollection_ExtendedString aType = HYDROData_Tool::toExtString( theType );
if( aMap->HasString( aType ) )
- return toQString( aMap->GetString( aType ) );
+ return HYDROData_Tool::toQString( aMap->GetString( aType ) );
else
return "";
}
void HYDROData_StricklerTable::SetAttrValue( const QString& theType, const QString& theAttrValue ) const
{
Handle( TDataStd_NamedData ) aMap = Map();
- TCollection_ExtendedString aType = toExtString( theType );
- aMap->SetString( aType, toExtString( theAttrValue ) );
+ TCollection_ExtendedString aType = HYDROData_Tool::toExtString( theType );
+ aMap->SetString( aType, HYDROData_Tool::toExtString( theAttrValue ) );
}
QString HYDROData_StricklerTable::GetType( const QString& theAttrValue ) const
{
Handle( TDataStd_NamedData ) aMap = Map();
- TCollection_ExtendedString anAttrValue = toExtString( theAttrValue );
+ TCollection_ExtendedString anAttrValue = HYDROData_Tool::toExtString( theAttrValue );
for( TDataStd_DataMapIteratorOfDataMapOfStringString it( aMap->GetStringsContainer() ); it.More(); it.Next() )
{
if( it.Value() == anAttrValue )
{
- QString aType = toQString( it.Key() );
+ QString aType = HYDROData_Tool::toQString( it.Key() );
return aType;
}
}
QColor HYDROData_StricklerTable::GetColor( const QString& theType ) const
{
Handle( TDataStd_NamedData ) aMap = Map();
- TCollection_ExtendedString aType = toExtString( theType );
+ TCollection_ExtendedString aType = HYDROData_Tool::toExtString( theType );
if( aMap->HasInteger( aType ) )
{
int aColorInt = aMap->GetInteger( aType );
void HYDROData_StricklerTable::SetColor( const QString& theType, const QColor& theColor ) const
{
Handle( TDataStd_NamedData ) aMap = Map();
- TCollection_ExtendedString aType = toExtString( theType );
+ TCollection_ExtendedString aType = HYDROData_Tool::toExtString( theType );
int r = theColor.red();
int g = theColor.green();
int b = theColor.blue();
HYDRODATA_EXPORT QColor GetColor( const QString& theType ) const;
HYDRODATA_EXPORT void SetColor( const QString& theType, const QColor& theColor ) const;
-private:
- TCollection_ExtendedString toExtString( const QString& ) const;
- QString toQString( const TCollection_ExtendedString& ) const;
-
private:
Handle(TDataStd_NamedData) Map() const;
};
aResShape = aGroupShapes.First();
return aResShape;
-}
\ No newline at end of file
+}
+
+TCollection_ExtendedString HYDROData_Tool::toExtString( const QString& theStr )
+{
+ TCollection_ExtendedString aRes;
+ if( !theStr.isEmpty() )
+ {
+ Standard_ExtString extStr = new Standard_ExtCharacter[ ( theStr.length() + 1 ) * 2 ];
+ memcpy( (void*)extStr, theStr.unicode(), theStr.length() * 2 );
+ ((short*)extStr)[theStr.length()] = '\0';
+ aRes = TCollection_ExtendedString( extStr );
+ delete [] extStr;
+ }
+ return aRes;
+}
+
+QString HYDROData_Tool::toQString( const TCollection_ExtendedString& theStr )
+{
+ return QString( (QChar*)theStr.ToExtString(), theStr.Length() );
+}
*/
static TopoDS_Shape getFirstShapeFromGroup( const HYDROData_SequenceOfObjects& theGroups,
const int theGroupId );
+
+ static TCollection_ExtendedString toExtString( const QString& );
+ static QString toQString( const TCollection_ExtendedString& );
};
inline bool ValuesEquals( const double& theFirst, const double& theSecond )