From: mkr Date: Fri, 23 Oct 2015 08:22:19 +0000 (+0300) Subject: Merge branch 'BR_LAND_COVER_MAP' of ssh://git.salome-platform.org/modules/hydro into... X-Git-Tag: v1.5~75 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=9c947f35615e69e9e54a8c4b074dd1f2be13689c;hp=35284afc5a9d72627ca011ef09ff37d4e15437b9;p=modules%2Fhydro.git Merge branch 'BR_LAND_COVER_MAP' of ssh://git.salome-platform.org/modules/hydro into BR_LAND_COVER_MAP --- diff --git a/CMake/UsePyQt4EXT.cmake b/CMake/UsePyQt4EXT.cmake index c85230fe..bd1875f6 100644 --- a/CMake/UsePyQt4EXT.cmake +++ b/CMake/UsePyQt4EXT.cmake @@ -177,6 +177,9 @@ MACRO(PYQT4_WRAP_SIP_EXT outfiles) LIST(APPEND _output ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyHYDROData_StricklerTable.cc) SET(${outfiles} ${${outfiles}} ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyHYDROData_StricklerTable.cc) + + LIST(APPEND _output ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyHYDROData_LandCoverMap.cc) + SET(${outfiles} ${${outfiles}} ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyHYDROData_LandCoverMap.cc) ADD_CUSTOM_COMMAND( OUTPUT ${_output} diff --git a/src/HYDROData/HYDROData_BSplineOperation.cxx b/src/HYDROData/HYDROData_BSplineOperation.cxx index 058005d9..64ae37d4 100644 --- a/src/HYDROData/HYDROData_BSplineOperation.cxx +++ b/src/HYDROData/HYDROData_BSplineOperation.cxx @@ -23,9 +23,7 @@ #include #include -#ifndef LIGHT_MODE #include -#endif Handle(Geom_BSplineCurve) HYDROData_BSplineOperation::ComputeCurve( const NCollection_Sequence& thePoints, @@ -58,11 +56,9 @@ Handle(Geom_BSplineCurve) HYDROData_BSplineOperation::ComputeCurve( // compute BSpline Handle(Geom_BSplineCurve) aBSpline; -#ifndef LIGHT_MODE if( CurveCreator_Utils::constructBSpline( aHCurvePoints, theIsClosed, aBSpline ) ) return aBSpline; else -#endif return Handle(Geom_BSplineCurve)(); } diff --git a/src/HYDROData/HYDROData_Document.cxx b/src/HYDROData/HYDROData_Document.cxx index 0cf4c403..93457716 100644 --- a/src/HYDROData/HYDROData_Document.cxx +++ b/src/HYDROData/HYDROData_Document.cxx @@ -267,6 +267,7 @@ bool HYDROData_Document::DumpToPython( const QString& theFileName, aRes = aRes && dumpPartitionToPython( aFile, theIsMultiFile, aTreatedObjects, KIND_CHANNEL ); aRes = aRes && dumpPartitionToPython( aFile, theIsMultiFile, aTreatedObjects, KIND_DIGUE ); aRes = aRes && dumpPartitionToPython( aFile, theIsMultiFile, aTreatedObjects, KIND_OBSTACLE ); + aRes = aRes && dumpPartitionToPython( aFile, theIsMultiFile, aTreatedObjects, KIND_LAND_COVER_MAP ); aRes = aRes && dumpPartitionToPython( aFile, theIsMultiFile, aTreatedObjects, KIND_CALCULATION ); // Dump code to close python fuction diff --git a/src/HYDROData/HYDROData_Entity.cxx b/src/HYDROData/HYDROData_Entity.cxx index 99667f31..f0b9e5fb 100644 --- a/src/HYDROData/HYDROData_Entity.cxx +++ b/src/HYDROData/HYDROData_Entity.cxx @@ -165,6 +165,8 @@ void HYDROData_Entity::Changed( Geometry theChangedGeometry ) for ( ; anIter.More(); anIter.Next() ) { Handle(HYDROData_Entity) anObject = anIter.Current(); + if( anObject.IsNull() ) + continue; HYDROData_SequenceOfObjects aRefSeq = anObject->GetAllReferenceObjects(); for ( int i = 1, n = aRefSeq.Length(); i <= n; ++i ) { diff --git a/src/HYDROData/HYDROData_LandCoverMap.cxx b/src/HYDROData/HYDROData_LandCoverMap.cxx index d7703a87..a429e381 100644 --- a/src/HYDROData/HYDROData_LandCoverMap.cxx +++ b/src/HYDROData/HYDROData_LandCoverMap.cxx @@ -208,7 +208,7 @@ HYDROData_LandCoverMap::DBFStatus HYDROData_LandCoverMap::ImportDBF( const QStri const QString& theFieldName, const QStringList& theDBFValues, const QStringList& theStricklerTypes, - QMap theIndices ) + const QList& theIndices ) { if (theDBFValues.size() != theStricklerTypes.size()) return DBFStatus_DIFF_SIZE_ERROR; @@ -749,3 +749,27 @@ TopoDS_Face HYDROData_LandCoverMap::FindByPoint( const gp_Pnt2d& thePoint, QStri theType = ""; return TopoDS_Face(); } + +/** + Dump to Python + @param theTreatedObjects the map of treated objects +*/ +QStringList HYDROData_LandCoverMap::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const +{ + QStringList aResList = dumpObjectCreation( theTreatedObjects ); + QString aName = GetObjPyName(); + + //Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis(); + //setPythonReferenceObject( theTreatedObjects, aResList, aHydAxis, "SetHydraulicAxis" ); + + //HYDROData_SequenceOfObjects aSeqOfProfiles = GetProfiles(); + //for ( int i = 1, aNb = aSeqOfProfiles.Size(); i <= aNb; ++i ) + //{ + //const Handle(HYDROData_Entity) aProfile = aSeqOfProfiles.Value( i ); + //setPythonReferenceObject( theTreatedObjects, aResList, aProfile, "AddProfile" ); + //} + + //TODO + + return aResList; +} diff --git a/src/HYDROData/HYDROData_LandCoverMap.h b/src/HYDROData/HYDROData_LandCoverMap.h index 2439c2de..cf6b7ca5 100644 --- a/src/HYDROData/HYDROData_LandCoverMap.h +++ b/src/HYDROData/HYDROData_LandCoverMap.h @@ -21,7 +21,6 @@ #include #include -#include DEFINE_STANDARD_HANDLE( HYDROData_LandCoverMap, HYDROData_Entity ) @@ -78,23 +77,23 @@ public: DBFStatus_NO_DBFVALUES_CORRESPONDENCE_WARNING }; - HYDROData_LandCoverMap(); - ~HYDROData_LandCoverMap(); + HYDRODATA_EXPORT HYDROData_LandCoverMap(); + HYDRODATA_EXPORT virtual ~HYDROData_LandCoverMap(); - virtual const ObjectKind GetKind() const; + HYDRODATA_EXPORT virtual const ObjectKind GetKind() const; - DBFStatus ImportDBF( const QString& theDBFFileName, - const QString& theFieldName, - const QStringList& DBFValues, - const QStringList& StricklerTypes, - QMap theIndices ); + HYDRODATA_EXPORT DBFStatus ImportDBF( const QString& theDBFFileName, + const QString& theFieldName, + const QStringList& DBFValues, + const QStringList& StricklerTypes, + const QList& theIndices ); - void ExportDBF( const QString& theDBFFileName, - const QString& theFieldName, - const QStringList& theDBFValues, - const QStringList& theStricklerTypes) const; + HYDRODATA_EXPORT void ExportDBF( const QString& theDBFFileName, + const QString& theFieldName, + const QStringList& theDBFValues, + const QStringList& theStricklerTypes ) const; - bool ExportTelemac( const QString& theFileName, double theDeflection ) const; + HYDRODATA_EXPORT bool ExportTelemac( const QString& theFileName, double theDeflection ) const; HYDRODATA_EXPORT bool Add( const Handle( HYDROData_Object )&, const QString& theType ); HYDRODATA_EXPORT bool Add( const Handle( HYDROData_PolylineXY )&, const QString& theType ); @@ -105,10 +104,12 @@ public: HYDRODATA_EXPORT bool Split( const Handle( HYDROData_PolylineXY )& ); HYDRODATA_EXPORT bool Merge( const TopTools_ListOfShape&, const QString& theType ); - TopoDS_Face FindByPoint( const gp_Pnt2d&, QString& theType ) const; + HYDRODATA_EXPORT TopoDS_Face FindByPoint( const gp_Pnt2d&, QString& theType ) const; HYDRODATA_EXPORT TopoDS_Shape GetShape() const; + HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const; + protected: void SetShape( const TopoDS_Shape& ); diff --git a/src/HYDROData/HYDROData_Object.cxx b/src/HYDROData/HYDROData_Object.cxx index 78f734ea..20eead85 100644 --- a/src/HYDROData/HYDROData_Object.cxx +++ b/src/HYDROData/HYDROData_Object.cxx @@ -374,3 +374,26 @@ void HYDROData_Object::SetIsSubmersible( bool isSubmersible ) const { TDataStd_Integer::Set( myLab, isSubmersible ? 1 : 0 ); } + +void HYDROData_Object::GetBoundaries( QList& theBoundShapes, + QStringList& theBoundNames ) const +{ + HYDROData_SequenceOfObjects aGroups = GetGroups(); + HYDROData_SequenceOfObjects::Iterator anIter( aGroups ); + for ( ; anIter.More(); anIter.Next() ) + { + Handle(HYDROData_ShapesGroup) aGroup = + Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() ); + if( aGroup.IsNull() ) + continue; + + QString aName = aGroup->GetName(); + TopTools_SequenceOfShape aShapes; + aGroup->GetShapes( aShapes ); + for( int i=1, n=aShapes.Length(); i<=n; i++ ) + { + theBoundShapes.append( aShapes( i ) ); + theBoundNames.append( aName ); + } + } +} diff --git a/src/HYDROData/HYDROData_Object.h b/src/HYDROData/HYDROData_Object.h index aa85d5ac..0c217f27 100644 --- a/src/HYDROData/HYDROData_Object.h +++ b/src/HYDROData/HYDROData_Object.h @@ -160,6 +160,9 @@ public: HYDRODATA_EXPORT bool IsSubmersible() const; HYDRODATA_EXPORT void SetIsSubmersible( bool ) const; + HYDRODATA_EXPORT virtual void GetBoundaries( QList& theBoundShapes, + QStringList& theBoundNames ) const; + protected: /** diff --git a/src/HYDROData/HYDROData_PolylineOperator.cxx b/src/HYDROData/HYDROData_PolylineOperator.cxx index 7e44abef..0bc2d326 100644 --- a/src/HYDROData/HYDROData_PolylineOperator.cxx +++ b/src/HYDROData/HYDROData_PolylineOperator.cxx @@ -19,6 +19,7 @@ #include #include #include +#include #ifndef LIGHT_MODE #include @@ -46,7 +47,8 @@ #include #include #include -#include +#include +#include #include template void append( std::vector& theList, const std::vector& theList2 ) @@ -80,8 +82,9 @@ bool HYDROData_PolylineOperator::Split( const Handle( HYDROData_Document )& theD for( int i=0, n=aCurves.size(); i aCurvesList; - Split(aCurves[i], thePoint, theTolerance, aCurvesList); - bool isLocalOK = CreatePolylines( theDoc, thePolyline->GetName(), aCurvesList, true ); + Split( aCurves[i], thePoint, theTolerance, aCurvesList ); + bool isLocalOK = CreatePolylines( theDoc, thePolyline->GetName(), + aCurvesList, true, thePolyline->GetWireColor() ); isOK = isOK && isLocalOK; } return isOK; @@ -160,7 +163,7 @@ bool HYDROData_PolylineOperator::Merge( const Handle( HYDROData_Document )& theD std::vector aPolylines(1); aPolylines[0] = aWireSet; - CreatePolylines(theDoc, theName, aPolylines, false); + CreatePolylines( theDoc, theName, aPolylines, false, QColor() ); return true; } @@ -228,7 +231,7 @@ bool HYDROData_PolylineOperator::split( const Handle( HYDROData_Document )& theD } } - CreatePolylines(theDoc, thePolyline->GetName(), aResult, true); + CreatePolylines( theDoc, thePolyline->GetName(), aResult, true, thePolyline->GetWireColor() ); return true; } @@ -280,7 +283,8 @@ void HYDROData_PolylineOperator::Split( bool HYDROData_PolylineOperator::CreatePolylines( const Handle( HYDROData_Document )& theDoc, const QString& theNamePrefix, const std::vector& theShapes, - bool isUseIndices ) + bool isUseIndices, + const QColor& theColor ) { if( theDoc.IsNull() ) return false; @@ -307,6 +311,9 @@ bool HYDROData_PolylineOperator::CreatePolylines( const Handle( HYDROData_Docume { aPolyline->SetName( theNamePrefix ); } + + if( theColor.isValid() ) + aPolyline->SetWireColor( theColor ); } return true; } @@ -412,3 +419,43 @@ double HYDROData_PolylineOperator::ReduceDeflection( } return aMaxDefl; } + +bool HYDROData_PolylineOperator::Extract( const Handle(HYDROData_Document)& theDocument, + const Handle(HYDROData_Object)& theObject ) +{ + if( theObject.IsNull() || theDocument.IsNull() ) + return false; + + QList aBoundShapes; + QStringList aBoundNames; + + theObject->GetBoundaries( aBoundShapes, aBoundNames ); + + for( int i=0, n=aBoundShapes.size(); iCreateObject( KIND_POLYLINEXY ) ); + + if( aPolyline.IsNull() ) + return false; + + aPolyline->SetShape( aShape ); + + int anIndex = 0; + QString aName = aBoundName; + while( !theDocument->FindObjectByName( aName ).IsNull() ) + { + anIndex++; + aName = aBoundName + "_" + QString::number( anIndex ); + } + aPolyline->SetName( aName ); + } + + return true; +} diff --git a/src/HYDROData/HYDROData_PolylineOperator.h b/src/HYDROData/HYDROData_PolylineOperator.h index 8e27796c..eefac88b 100644 --- a/src/HYDROData/HYDROData_PolylineOperator.h +++ b/src/HYDROData/HYDROData_PolylineOperator.h @@ -26,6 +26,7 @@ class Handle( HYDROData_Document ); class HYDROData_TopoCurve; +class Handle(HYDROData_Object); class HYDRODATA_EXPORT HYDROData_PolylineOperator { @@ -64,6 +65,9 @@ public: HYDROData_TopoCurve& theCurve, int& thePieceCount); + bool Extract( const Handle(HYDROData_Document)& theDocument, + const Handle(HYDROData_Object)& theObject ); + protected: bool split( const Handle( HYDROData_Document )& theDoc, const Handle( HYDROData_PolylineXY )& thePolyline, @@ -81,7 +85,8 @@ protected: static bool CreatePolylines( const Handle( HYDROData_Document )& theDoc, const QString& theNamePrefix, const std::vector& theShape, - bool isUseIndices ); + bool isUseIndices, + const QColor& theColor ); }; #endif diff --git a/src/HYDROData/HYDROData_PolylineXY.cxx b/src/HYDROData/HYDROData_PolylineXY.cxx index d47f2cb8..559947e6 100755 --- a/src/HYDROData/HYDROData_PolylineXY.cxx +++ b/src/HYDROData/HYDROData_PolylineXY.cxx @@ -29,6 +29,7 @@ #include #include #include +#include #ifndef LIGHT_MODE #include @@ -40,6 +41,7 @@ #include #include +#include #include @@ -56,6 +58,7 @@ #include #include +#include #include #include @@ -118,7 +121,8 @@ IMPLEMENT_STANDARD_HANDLE(HYDROData_PolylineXY, HYDROData_IPolyline) IMPLEMENT_STANDARD_RTTIEXT(HYDROData_PolylineXY, HYDROData_IPolyline) HYDROData_PolylineXY::HYDROData_PolylineXY() -: HYDROData_IPolyline() +: HYDROData_IPolyline(), + myIsInCustomFlag( false ) { } @@ -253,7 +257,9 @@ bool convertEdgeToSection( const TopoDS_Edge& NCollection_Sequence& theSectTypes, NCollection_Sequence& theSectClosures, NCollection_Sequence& theSectPoints, - const bool theIsCanBeClosed ) + bool IsCanBeClosed, + bool IsInterpolationAllowed, + double theDeflection ) { Standard_Real aFirst = 0.0, aLast = 0.0; Handle(Geom_Curve) anEdgeGeomCurve = BRep_Tool::Curve( theEdge, aFirst, aLast ); @@ -266,7 +272,7 @@ bool convertEdgeToSection( const TopoDS_Edge& HYDROData_PolylineXY::SectionType aSectionType = HYDROData_PolylineXY::SECTION_POLYLINE; HYDROData_PolylineXY::PointsList aPointsList; - if ( anEdgeGeomCurve->IsKind( STANDARD_TYPE(Geom_Line) ) ) + if( anEdgeGeomCurve->IsKind( STANDARD_TYPE(Geom_Line) ) ) { Handle(Geom_Line) aGeomLine = Handle(Geom_Line)::DownCast( anEdgeGeomCurve ); @@ -280,28 +286,22 @@ bool convertEdgeToSection( const TopoDS_Edge& HYDROData_PolylineXY::Point aSectLastPoint( aLastPoint.X(), aLastPoint.Y() ); aPointsList.Append( aSectLastPoint ); } - else if ( anEdgeGeomCurve->IsKind( STANDARD_TYPE(Geom_BSplineCurve) ) ) + else if ( anEdgeGeomCurve->IsKind( STANDARD_TYPE(Geom_BSplineCurve) ) || IsInterpolationAllowed ) { aSectionType = HYDROData_PolylineXY::SECTION_SPLINE; - Handle(Geom_BSplineCurve) aGeomSpline = - Handle(Geom_BSplineCurve)::DownCast( anEdgeGeomCurve ); + BRepAdaptor_Curve anAdaptorCurve( theEdge ); + GCPnts_QuasiUniformDeflection aDiscrete( anAdaptorCurve, theDeflection ); - int aNbKnots = aGeomSpline->NbKnots(); + int aNbPoints = aDiscrete.NbPoints(); - TColStd_Array1OfReal aSplineKnots( 1, aNbKnots ); - aGeomSpline->Knots( aSplineKnots ); + // Decrease the number of imported poles because of last one + // pole is the closing point which are the start point + if ( anIsEdgeClosed ) aNbPoints--; - // Decrease the number of imported knots because of last one - // knot is the closing point which are the start point - if ( anIsEdgeClosed ) aNbKnots--; - - for ( int i = 1; i <= aNbKnots; ++i ) + for ( int i = 1; i <= aNbPoints; ++i ) { - const Standard_Real& aKnot = aSplineKnots.Value( i ); - - gp_Pnt aPoint; - aGeomSpline->D0( aKnot, aPoint ); + const gp_Pnt& aPoint = aDiscrete.Value( i ); HYDROData_PolylineXY::Point aSectPoint( aPoint.X(), aPoint.Y() ); aPointsList.Append( aSectPoint ); @@ -324,7 +324,9 @@ bool convertEdgeToSection( const TopoDS_Edge& return true; } -bool HYDROData_PolylineXY::ImportShape( const TopoDS_Shape& theShape ) +bool HYDROData_PolylineXY::ImportShape( const TopoDS_Shape& theShape, + bool IsInterpolationAllowed, + double theDeviation ) { if ( theShape.IsNull() ) return false; @@ -341,7 +343,8 @@ bool HYDROData_PolylineXY::ImportShape( const TopoDS_Shape& theShape ) if ( theShape.ShapeType() == TopAbs_EDGE ) { TopoDS_Edge anEdge = TopoDS::Edge( theShape ); - anIsCanBeImported = convertEdgeToSection( anEdge, aSectNames, aSectTypes, aSectClosures, aSectPoints, true ); + anIsCanBeImported = convertEdgeToSection( anEdge, aSectNames, aSectTypes, + aSectClosures, aSectPoints, true, IsInterpolationAllowed, theDeviation ); } else if ( theShape.ShapeType() == TopAbs_WIRE ) { @@ -352,7 +355,8 @@ bool HYDROData_PolylineXY::ImportShape( const TopoDS_Shape& theShape ) for ( int i = 1, n = anEdges.Length(); i <= n && anIsCanBeImported; ++i ) { TopoDS_Edge aWireEdge = TopoDS::Edge( anEdges.Value( i ) ); - anIsCanBeImported = convertEdgeToSection( aWireEdge, aSectNames, aSectTypes, aSectClosures, aSectPoints, false ); + anIsCanBeImported = convertEdgeToSection( aWireEdge, aSectNames, aSectTypes, + aSectClosures, aSectPoints, false, IsInterpolationAllowed, theDeviation ); } } @@ -835,6 +839,11 @@ void HYDROData_PolylineXY::GetSections( NCollection_Sequence( this )->Interpolate(); + } + Handle(TDataStd_ExtStringList) aNamesList; Handle(TDataStd_IntegerList) aTypesList; Handle(TDataStd_BooleanList) aClosuresList; @@ -1075,7 +1084,7 @@ HYDROData_PolylineXY::PointsList HYDROData_PolylineXY::GetPoints( const int theS if( IsCustom() ) { - //TODO: make interpolation to fill the list + const_cast( this )->Interpolate(); } Handle(TDataStd_RealList) aListX, aListY; @@ -1177,12 +1186,22 @@ void HYDROData_PolylineXY::Transform( const QTransform& theTrsf ) bool HYDROData_PolylineXY::IsCustom() const { + if( myIsInCustomFlag ) + return false; + bool isNull = GetShape().IsNull(); int aNbPoints = 0; - //TODO: to check if there is no points - //for( int i=0, n=NbSections(); i( this ); + aThat->myIsInCustomFlag = true; + for( int i=0, n=NbSections(); imyIsInCustomFlag = false; return !isNull && aNbPoints == 0; } + +void HYDROData_PolylineXY::Interpolate() +{ + ImportShape( GetShape(), true ); +} diff --git a/src/HYDROData/HYDROData_PolylineXY.h b/src/HYDROData/HYDROData_PolylineXY.h index 57ff8cad..611a2a30 100644 --- a/src/HYDROData/HYDROData_PolylineXY.h +++ b/src/HYDROData/HYDROData_PolylineXY.h @@ -127,7 +127,9 @@ public: /** * Returns the 3D presentation of all points. */ - HYDRODATA_EXPORT virtual bool ImportShape( const TopoDS_Shape& theShape ); + HYDRODATA_EXPORT virtual bool ImportShape( const TopoDS_Shape& theShape, + bool IsInterpolationAllowed = false, + double theDeviation = 1E-3 ); /** * Returns flag indicating that polyline can be edited or not. @@ -297,6 +299,8 @@ protected: */ HYDRODATA_EXPORT virtual void setEditable( const bool theIsEditable ); + HYDRODATA_EXPORT void Interpolate(); + protected: friend class HYDROData_Profile; @@ -312,6 +316,9 @@ protected: * Destructs properties of the object and object itself, removes it from the document. */ HYDRODATA_EXPORT ~HYDROData_PolylineXY(); + +private: + bool myIsInCustomFlag; }; #endif diff --git a/src/HYDROData/HYDROData_ShapeFile.cxx b/src/HYDROData/HYDROData_ShapeFile.cxx index 3aa6ac7e..357ceedd 100644 --- a/src/HYDROData/HYDROData_ShapeFile.cxx +++ b/src/HYDROData/HYDROData_ShapeFile.cxx @@ -51,6 +51,10 @@ #include #include +#ifdef WIN32 + #pragma warning( disable: 4996 ) +#endif + HYDROData_ShapeFile::HYDROData_ShapeFile() : myHSHP(NULL) { } diff --git a/src/HYDROData/HYDROData_Tool.cxx b/src/HYDROData/HYDROData_Tool.cxx index def682d9..f6f0f5a8 100644 --- a/src/HYDROData/HYDROData_Tool.cxx +++ b/src/HYDROData/HYDROData_Tool.cxx @@ -282,6 +282,14 @@ Quantity_Color HYDROData_Tool::toOccColor( const QColor& theColor ) return Quantity_Color( r, g, b, Quantity_TOC_RGB ); } +QColor HYDROData_Tool::toQtColor( const Quantity_Color& theColor ) +{ + int r = 255 * theColor.Red(); + int g = 255 * theColor.Green(); + int b = 255 * theColor.Blue(); + return QColor( r, g, b ); +} + std::ostream& operator<<( std::ostream& theStream, const QString& theText ) { theStream << theText.toStdString(); @@ -306,3 +314,17 @@ std::ostream& operator<<( std::ostream& theStream, const TopoDS_Face& theFace ) return theStream; } +std::ostream& operator<<( std::ostream& theStream, const gp_XY& theXY ) +{ + theStream << "(" << theXY.X() << "; " << theXY.Y() << ")"; + return theStream; +} + +bool operator == ( const gp_XY& thePoint1, const gp_XY& thePoint2 ) +{ + const double EPS = 1E-3; + return + fabs( thePoint1.X() - thePoint2.X() ) < EPS && + fabs( thePoint1.Y() - thePoint2.Y() ) < EPS; + +} diff --git a/src/HYDROData/HYDROData_Tool.h b/src/HYDROData/HYDROData_Tool.h index efff055d..b9b6d6d7 100644 --- a/src/HYDROData/HYDROData_Tool.h +++ b/src/HYDROData/HYDROData_Tool.h @@ -119,7 +119,8 @@ public: static TCollection_ExtendedString toExtString( const QString& ); static QString toQString( const TCollection_ExtendedString& ); - static Quantity_Color toOccColor( const QColor& ); + static Quantity_Color toOccColor( const QColor& ); + static QColor toQtColor( const Quantity_Color& ); }; inline bool ValuesEquals( const double& theFirst, const double& theSecond ) @@ -142,6 +143,8 @@ HYDRODATA_EXPORT std::ostream& operator<<( std::ostream& theStream, const QStrin HYDRODATA_EXPORT std::ostream& operator<<( std::ostream& theStream, const QColor& theText ); HYDRODATA_EXPORT std::ostream& operator<<( std::ostream& theStream, const TopoDS_Shape& theShape ); HYDRODATA_EXPORT std::ostream& operator<<( std::ostream& theStream, const TopoDS_Face& theFace ); +HYDRODATA_EXPORT bool operator == ( const gp_XY& thePoint1, const gp_XY& thePoint2 ); +HYDRODATA_EXPORT std::ostream& operator<<( std::ostream& theStream, const gp_XY& theXY ); #endif diff --git a/src/HYDROGUI/HYDROGUI_LandCoverMapPrs.cxx b/src/HYDROGUI/HYDROGUI_LandCoverMapPrs.cxx index 7a005c24..6f654a6d 100644 --- a/src/HYDROGUI/HYDROGUI_LandCoverMapPrs.cxx +++ b/src/HYDROGUI/HYDROGUI_LandCoverMapPrs.cxx @@ -21,11 +21,16 @@ #include #include #include +#include #include +#include #include #include #include +const Quantity_Color EDGES_COLOR = Quantity_NOC_WHITE; +const int HILIGHT_ISO_NB = 10; + IMPLEMENT_STANDARD_HANDLE( HYDROGUI_LandCoverMapPrs, AIS_ColoredShape ) IMPLEMENT_STANDARD_RTTIEXT( HYDROGUI_LandCoverMapPrs, AIS_ColoredShape ) @@ -33,6 +38,8 @@ HYDROGUI_LandCoverMapPrs::HYDROGUI_LandCoverMapPrs( const Handle(HYDROData_LandC : AIS_ColoredShape( theMap->GetShape() ) { SetLandCoverMap( theMap ); + SetAutoHilight( Standard_False ); + SetHilightAttributes( EDGES_COLOR ); } HYDROGUI_LandCoverMapPrs::~HYDROGUI_LandCoverMapPrs() @@ -135,13 +142,11 @@ void HYDROGUI_LandCoverMapPrs::Compute( const Handle(PrsMgr_PresentationManager3 { thePresentation->Clear(); - Quantity_Color anEdgeColor = Quantity_NOC_WHITE; - myDrawer->UIsoAspect()->SetNumber( 0 ); myDrawer->VIsoAspect()->SetNumber( 0 ); - myDrawer->LineAspect()->SetColor( anEdgeColor ); - myDrawer->FaceBoundaryAspect()->SetColor( anEdgeColor ); - myDrawer->FreeBoundaryAspect()->SetColor( anEdgeColor ); + myDrawer->LineAspect()->SetColor( EDGES_COLOR ); + myDrawer->FaceBoundaryAspect()->SetColor( EDGES_COLOR ); + myDrawer->FreeBoundaryAspect()->SetColor( EDGES_COLOR ); switch( theMode ) { @@ -155,3 +160,34 @@ void HYDROGUI_LandCoverMapPrs::Compute( const Handle(PrsMgr_PresentationManager3 StdPrs_WFDeflectionShape::Add( thePresentation, Shape(), myDrawer ); } +void HYDROGUI_LandCoverMapPrs::HilightSelected( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, + const SelectMgr_SequenceOfOwner& theOwners ) +{ + Handle(Prs3d_Presentation) aSelectPrs = GetSelectPresentation( thePresentationManager ); + + SetHilightAttributes( EDGES_COLOR ); + + for( int i=1, n=theOwners.Length(); i<=n; i++ ) + { + Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast( theOwners.Value( i ) ); + if( !anOwner.IsNull() ) + StdPrs_WFDeflectionShape::Add( aSelectPrs, anOwner->Shape(), HilightAttributes() ); + } + + HilightAttributes()->UIsoAspect()->SetNumber( 0 ); + HilightAttributes()->VIsoAspect()->SetNumber( 0 ); + + aSelectPrs->SetDisplayPriority( 9 ); + aSelectPrs->Display(); +} + +void HYDROGUI_LandCoverMapPrs::SetHilightAttributes( const Quantity_Color& theEdgesColor ) +{ + HilightAttributes()->UIsoAspect()->SetNumber( HILIGHT_ISO_NB ); + HilightAttributes()->UIsoAspect()->SetColor( theEdgesColor ); + HilightAttributes()->VIsoAspect()->SetNumber( HILIGHT_ISO_NB ); + HilightAttributes()->VIsoAspect()->SetColor( theEdgesColor ); + HilightAttributes()->LineAspect()->SetColor( theEdgesColor ); + HilightAttributes()->FaceBoundaryAspect()->SetColor( theEdgesColor ); + HilightAttributes()->FreeBoundaryAspect()->SetColor( theEdgesColor ); +} diff --git a/src/HYDROGUI/HYDROGUI_LandCoverMapPrs.h b/src/HYDROGUI/HYDROGUI_LandCoverMapPrs.h index 0e9888a1..e1acc832 100644 --- a/src/HYDROGUI/HYDROGUI_LandCoverMapPrs.h +++ b/src/HYDROGUI/HYDROGUI_LandCoverMapPrs.h @@ -47,10 +47,14 @@ public: const Handle(Prs3d_Presentation)& thePresentation, const Standard_Integer theMode ); + virtual void HilightSelected( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, + const SelectMgr_SequenceOfOwner& theOwners ); + Quantity_Color GetColor( const QString& theStricklerType ) const; protected: void UpdateColors(); + void SetHilightAttributes( const Quantity_Color& theEdgesColor ); private: Handle(HYDROData_LandCoverMap) myLCMap; diff --git a/src/HYDROGUI/HYDROGUI_Polyline.cxx b/src/HYDROGUI/HYDROGUI_Polyline.cxx index 91e0a06a..4f070b47 100644 --- a/src/HYDROGUI/HYDROGUI_Polyline.cxx +++ b/src/HYDROGUI/HYDROGUI_Polyline.cxx @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -82,8 +83,11 @@ void HYDROGUI_Polyline::Compute(const Handle(PrsMgr_PresentationManager3d)& aPre aPrs->Clear(); Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup( aPrs ); - Handle(Graphic3d_AspectLine3d) anAspect = Attributes()->FaceBoundaryAspect()->Aspect(); - aGroup->SetGroupPrimitivesAspect( anAspect ); + Quantity_Color aColor; + Aspect_TypeOfLine aType; + Standard_Real anWidth; + Attributes()->LineAspect()->Aspect()->Values( aColor, aType, anWidth ); + Handle(Graphic3d_AspectLine3d) anAspect = new Graphic3d_AspectLine3d( aColor, aType, anWidth ); TopExp_Explorer Exp1 ( myshape, TopAbs_EDGE ); for ( ; Exp1.More(); Exp1.Next() ) @@ -91,7 +95,10 @@ void HYDROGUI_Polyline::Compute(const Handle(PrsMgr_PresentationManager3d)& aPre TopoDS_Edge anEdge = TopoDS::Edge( Exp1.Current() ); Handle( Graphic3d_ArrayOfPolylines ) anArray = BuildEdgePresentation( anEdge, 0.1 ); if( !anArray.IsNull() ) - aGroup->AddPrimitiveArray ( anArray ); + { + aGroup->SetPrimitivesAspect( anAspect ); + aGroup->AddPrimitiveArray( anArray ); + } } diff --git a/src/HYDROGUI/HYDROGUI_PolylineExtractionOp.cxx b/src/HYDROGUI/HYDROGUI_PolylineExtractionOp.cxx index ac0a39ad..591ae2de 100644 --- a/src/HYDROGUI/HYDROGUI_PolylineExtractionOp.cxx +++ b/src/HYDROGUI/HYDROGUI_PolylineExtractionOp.cxx @@ -16,27 +16,12 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -#include "HYDROGUI_PolylineExtractionOp.h" - -#include - -#include "HYDROGUI_Module.h" -#include "HYDROGUI_Operations.h" -#include "HYDROGUI_Tool.h" -#include "HYDROGUI_UpdateFlags.h" - -#include +#include +#include +#include +#include #include -#include -#include - -#include -#include - -#include -#include - -#include +#include HYDROGUI_PolylineExtractionOp::HYDROGUI_PolylineExtractionOp( HYDROGUI_Module* theModule ) : HYDROGUI_Operation( theModule ) @@ -59,124 +44,16 @@ void HYDROGUI_PolylineExtractionOp::startOperation() if ( aSeq.IsEmpty() ) return; + startDocOperation(); + HYDROData_PolylineOperator anOp; for ( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ ) { - Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex ); - if ( anObject.IsNull() ) - continue; - - ShapeInfoList aList; - - switch ( anObject->GetKind() ) - { - case KIND_STREAM: - aList = extract( Handle(HYDROData_Stream)::DownCast( anObject ) ); - break; - case KIND_DIGUE: - case KIND_CHANNEL: - aList = extract( Handle(HYDROData_Channel)::DownCast( anObject ) ); - break; - case KIND_OBSTACLE: - aList = extract( Handle(HYDROData_Obstacle)::DownCast( anObject ) ); - break; - } - - startDocOperation(); - - for ( ShapeInfoList::const_iterator it = aList.begin(); it != aList.end(); ++it ) - { - const ShapeInfo& inf = *it; - TopoDS_Shape aLine = inf.shape(); - QString aName = QString( "%1_%2" ).arg( anObject->GetName() ).arg( inf.name() ); - if ( !HYDROGUI_Tool::FindObjectByName( aModule, aName ).IsNull() ) - { - int num = 1; - while ( !HYDROGUI_Tool::FindObjectByName( aModule, aName + QString( "_%1" ).arg( num ) ).IsNull() ) - num++; - - aName += QString( "_%1" ).arg( num ); - } - - Handle(HYDROData_PolylineXY) aPolylineObj = Handle(HYDROData_PolylineXY)::DownCast( doc()->CreateObject( KIND_POLYLINEXY ) ); - if ( !aPolylineObj.IsNull() ) - { - aPolylineObj->SetName( aName ); - aPolylineObj->ImportShape( aLine ); - aPolylineObj->Update(); - } - } - - commitDocOperation(); + Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast( aSeq.Value( anIndex ) ); + if( !anObject.IsNull() ) + anOp.Extract( doc(), anObject ); } + commitDocOperation(); aModule->update( anUpdateFlags ); - commit(); } - -HYDROGUI_PolylineExtractionOp::ShapeInfoList HYDROGUI_PolylineExtractionOp::extract( const Handle(HYDROData_Stream)& theStream ) const -{ - ShapeInfoList aList; - if ( !theStream.IsNull() ) - { - aList.append( ShapeInfo( theStream->GetLeftShape(), QString( "Left bank" ) ) ); - aList.append( ShapeInfo( theStream->GetRightShape(), QString( "Right bank" ) ) ); - - HYDROData_SequenceOfObjects aProfiles = theStream->GetProfiles(); - for ( int i = 1; i <= aProfiles.Length(); i++ ) - { - Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast( aProfiles.Value( i ) ); - aList.append( ShapeInfo( aProfile->GetTopShape(), QString( "Profile_%1" ).arg( i ) ) ); - } - } - return aList; -} - -HYDROGUI_PolylineExtractionOp::ShapeInfoList HYDROGUI_PolylineExtractionOp::extract( const Handle(HYDROData_Channel)& aChannel ) const -{ - ShapeInfoList aList; - if ( !aChannel.IsNull() ) - { - HYDROData_SequenceOfObjects aGroups = aChannel->GetGroups(); - int aNum = qMin( aGroups.Length(), 2 ); - for ( int i = 1; i <= aNum; i++ ) - { - Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast( aGroups.Value( i ) ); - TopTools_SequenceOfShape aShapes; - aGroup->GetShapes( aShapes ); - if ( !aShapes.IsEmpty() ) - { - TopoDS_Wire aWire; - BRep_Builder aBuilder; - aBuilder.MakeWire( aWire ); - - for ( int s = 1; s <= aShapes.Length(); s++ ) - aBuilder.Add( aWire, aShapes.Value( s ) ); - aList.append( ShapeInfo( aWire, i > 1 ? "Right bank" : "Left bank" ) ); - } - } - } - return aList; -} - -HYDROGUI_PolylineExtractionOp::ShapeInfoList HYDROGUI_PolylineExtractionOp::extract( const Handle(HYDROData_Obstacle)& theObstacle ) const -{ - ShapeInfoList aList; - if ( !theObstacle.IsNull() ) - { - TopoDS_Wire aWire; - BRep_Builder aBuilder; - aBuilder.MakeWire( aWire ); - HYDROData_SequenceOfObjects aGroups = theObstacle->GetGroups(); - for ( int i = 1; i <= aGroups.Length(); i++ ) - { - Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast( aGroups.Value( i ) ); - TopTools_SequenceOfShape aShapes; - aGroup->GetShapes( aShapes ); - for ( int s = 1; s <= aShapes.Length(); s++ ) - aBuilder.Add( aWire, aShapes.Value( s ) ); - } - aList.append( ShapeInfo( aWire, QString( "Contour" ) ) ); - } - return aList; -} diff --git a/src/HYDROGUI/HYDROGUI_PolylineExtractionOp.h b/src/HYDROGUI/HYDROGUI_PolylineExtractionOp.h index 414799e5..1258e1f1 100644 --- a/src/HYDROGUI/HYDROGUI_PolylineExtractionOp.h +++ b/src/HYDROGUI/HYDROGUI_PolylineExtractionOp.h @@ -37,27 +37,7 @@ public: virtual ~HYDROGUI_PolylineExtractionOp(); protected: - virtual void startOperation(); - -private: - class ShapeInfo - { - public: - ShapeInfo( const TopoDS_Shape s, const QString& n ) : myShape( s ), myName( n ) {} - TopoDS_Shape shape() const { return myShape; } - QString name() const { return myName; } - - private: - TopoDS_Shape myShape; - QString myName; - }; - - typedef QList ShapeInfoList; - -private: - ShapeInfoList extract( const Handle(HYDROData_Stream)& ) const; - ShapeInfoList extract( const Handle(HYDROData_Channel)& ) const; - ShapeInfoList extract( const Handle(HYDROData_Obstacle)& ) const; + virtual void startOperation(); }; #endif diff --git a/src/HYDROPy/CMakeLists.txt b/src/HYDROPy/CMakeLists.txt index d91a5834..013a4a9e 100644 --- a/src/HYDROPy/CMakeLists.txt +++ b/src/HYDROPy/CMakeLists.txt @@ -92,6 +92,7 @@ SET(_sip_files2 HYDROData_Document.sip HYDROData_Application.sip HYDROData_IProfilesInterpolator.sip + HYDROData_LandCoverMap.sip ) # --- sources --- diff --git a/src/HYDROPy/HYDROData.sip b/src/HYDROPy/HYDROData.sip index e0235298..84f94621 100644 --- a/src/HYDROPy/HYDROData.sip +++ b/src/HYDROPy/HYDROData.sip @@ -47,40 +47,39 @@ %Include CAS/gp_XYZ.sip %Include CAS/NCollection_Sequence.sip %Include CAS/TCollection_AsciiString.sip -%Include HYDROData_SequenceOfObjects.sip -%Include HYDROData_IInterpolator.sip -%Include HYDROData_Entity.sip -%Include HYDROData_ShapesGroup.sip -%Include HYDROData_SplittedShapesGroup.sip -%Include HYDROData_IPolyline.sip -%Include HYDROData_IAltitudeObject.sip + %Include HYDROData_AltitudeObject.sip -%Include HYDROData_ObstacleAltitude.sip -%Include HYDROData_StreamAltitude.sip -%Include HYDROData_Object.sip -%Include HYDROData_Profile.sip -%Include HYDROData_Polyline3D.sip -%Include HYDROData_ProfileUZ.sip -%Include HYDROData_PolylineXY.sip +%Include HYDROData_Application.sip %Include HYDROData_ArtificialObject.sip -%Include HYDROData_Obstacle.sip +%Include HYDROData_Bathymetry.sip +%Include HYDROData_CalculationCase.sip %Include HYDROData_Channel.sip -%Include HYDROData_Digue.sip -%Include HYDROData_NaturalObject.sip %Include HYDROData_Confluence.sip -%Include HYDROData_River.sip -%Include HYDROData_Stream.sip +%Include HYDROData_Digue.sip +%Include HYDROData_Document.sip +%Include HYDROData_Entity.sip +%Include HYDROData_IAltitudeObject.sip +%Include HYDROData_IInterpolator.sip %Include HYDROData_Image.sip -%Include HYDROData_PolylineXY.sip -%Include HYDROData_Bathymetry.sip %Include HYDROData_ImmersibleZone.sip -%Include HYDROData_Zone.sip -%Include HYDROData_Region.sip -%Include HYDROData_CalculationCase.sip +%Include HYDROData_IPolyline.sip %Include HYDROData_IProfilesInterpolator.sip +%Include HYDROData_LandCoverMap.sip +%Include HYDROData_NaturalObject.sip +%Include HYDROData_Object.sip +%Include HYDROData_Obstacle.sip +%Include HYDROData_ObstacleAltitude.sip +%Include HYDROData_PolylineXY.sip +%Include HYDROData_Polyline3D.sip +%Include HYDROData_Profile.sip +%Include HYDROData_ProfileUZ.sip +%Include HYDROData_Region.sip +%Include HYDROData_River.sip +%Include HYDROData_SequenceOfObjects.sip +%Include HYDROData_ShapesGroup.sip +%Include HYDROData_SplittedShapesGroup.sip +%Include HYDROData_Stream.sip +%Include HYDROData_StreamAltitude.sip %Include HYDROData_StricklerTable.sip - -%Include HYDROData_Document.sip -%Include HYDROData_Application.sip - +%Include HYDROData_Zone.sip diff --git a/src/HYDROPy/HYDROData_AltitudeObject.sip b/src/HYDROPy/HYDROData_AltitudeObject.sip index da99346b..3ad15bd3 100644 --- a/src/HYDROPy/HYDROData_AltitudeObject.sip +++ b/src/HYDROPy/HYDROData_AltitudeObject.sip @@ -28,15 +28,6 @@ class HYDROData_AltitudeObject : public HYDROData_IAltitudeObject %End protected: - - /** - * Creates new object in the internal data structure. Use higher level objects - * to create objects with real content. - */ HYDROData_AltitudeObject(); - - /** - * Destructs properties of the object and object itself, removes it from the document. - */ ~HYDROData_AltitudeObject(); }; diff --git a/src/HYDROPy/HYDROData_Application.sip b/src/HYDROPy/HYDROData_Application.sip index d9499915..c34c8976 100644 --- a/src/HYDROPy/HYDROData_Application.sip +++ b/src/HYDROPy/HYDROData_Application.sip @@ -27,16 +27,9 @@ class HYDROData_Application #include %End -public: // useful methods inside of the package - - //! Retuns the application: one per process +public: static HYDROData_Application* GetApplication(); -public: // Redefined OCAF methods - //! Return name of resource (i.e. "Standard") const char* ResourcesName(); - //! Constructor - //! Use method GetInstance() method to obtain - //! the static instance of the object (or derive your own application) HYDROData_Application(); -}; \ No newline at end of file +}; diff --git a/src/HYDROPy/HYDROData_ArtificialObject.sip b/src/HYDROPy/HYDROData_ArtificialObject.sip index 87526ec3..0720b6c3 100644 --- a/src/HYDROPy/HYDROData_ArtificialObject.sip +++ b/src/HYDROPy/HYDROData_ArtificialObject.sip @@ -52,20 +52,7 @@ class HYDROData_ArtificialObject : public HYDROData_Object /Abstract/ } %End -public: - - protected: - - /** - * Creates new object in the internal data structure. Use higher level objects - * to create objects with real content. - */ HYDROData_ArtificialObject(); - - /** - * Destructs properties of the object and object itself, removes it from the document. - */ virtual ~HYDROData_ArtificialObject(); - }; diff --git a/src/HYDROPy/HYDROData_Bathymetry.sip b/src/HYDROPy/HYDROData_Bathymetry.sip index d9e4e108..e2302918 100644 --- a/src/HYDROPy/HYDROData_Bathymetry.sip +++ b/src/HYDROPy/HYDROData_Bathymetry.sip @@ -44,62 +44,19 @@ class HYDROData_Bathymetry : public HYDROData_IAltitudeObject %End public: - // Public methods to work with Bathymetry altitudes. - - /** - * Replace current altitude points by new one. - * \param thePoints the altitude points list - */ - virtual void SetAltitudePoints( const HYDROData_Bathymetry::AltitudePoints& ); - - /** - * Returns altitude points list. - * \return points list - */ + virtual void SetAltitudePoints( const HYDROData_Bathymetry::AltitudePoints& ); HYDROData_Bathymetry::AltitudePoints GetAltitudePoints() const; - /** - * Remove all altitude points. - */ - void RemoveAltitudePoints(); - + void RemoveAltitudePoints(); public: - // Public methods to work with files. - - /** - * Set flag indicating needs to invert altitude values - * \param theIsInverted new invert value - * \param theIsUpdate flag indicating necessity to update points - */ - void SetAltitudesInverted( const bool theIsInverted, - const bool theIsUpdate = true ); - - /** - * Returns flag indicating needs to invert altitude values. - */ - bool IsAltitudesInverted() const; - - /** - * Imports Bathymetry data from file. The supported file types: - * - xyz - * \param theFileName the path to file - * \return \c true if file has been successfully read - */ - bool ImportFromFile( const TCollection_AsciiString& theFileName ); + void SetAltitudesInverted( const bool theIsInverted, const bool theIsUpdate = true ); + bool IsAltitudesInverted() const; + bool ImportFromFile( const TCollection_AsciiString& theFileName ); protected: - - /** - * Creates new object in the internal data structure. Use higher level objects - * to create objects with real content. - */ HYDROData_Bathymetry(); - - /** - * Destructs properties of the object and object itself, removes it from the document. - */ ~HYDROData_Bathymetry(); }; diff --git a/src/HYDROPy/HYDROData_CalculationCase.sip b/src/HYDROPy/HYDROData_CalculationCase.sip index c1ebd5ce..9ed40198 100644 --- a/src/HYDROPy/HYDROData_CalculationCase.sip +++ b/src/HYDROPy/HYDROData_CalculationCase.sip @@ -108,7 +108,8 @@ public: /** * Removes reference geometry object from calculation case. */ - void RemoveGeometryObject( HYDROData_Object theObject ) [void ( const Handle_HYDROData_Object& )]; + void RemoveGeometryObject( HYDROData_Object theObject ) + [void ( const Handle_HYDROData_Object& )]; %MethodCode Handle(HYDROData_Object) aRef = Handle(HYDROData_Object)::DownCast( createHandle( a0 ) ); diff --git a/src/HYDROPy/HYDROData_LandCoverMap.sip b/src/HYDROPy/HYDROData_LandCoverMap.sip new file mode 100644 index 00000000..734565ea --- /dev/null +++ b/src/HYDROPy/HYDROData_LandCoverMap.sip @@ -0,0 +1,109 @@ +// Copyright (C) 2014-2015 EDF-R&D +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +%ExportedHeaderCode +#include +%End + +class HYDROData_LandCoverMap : public HYDROData_Entity +{ +%TypeHeaderCode +#include +%End + +%ConvertToSubClassCode + switch ( sipCpp->GetKind() ) + { + case KIND_LAND_COVER_MAP: + sipClass = sipClass_HYDROData_LandCoverMap; + break; + + default: + // We don't recognise the type. + sipClass = NULL; + } +%End + +public: + enum DBFStatus + { + DBFStatus_OK, + DBFStatus_DIFF_SIZE_ERROR, + DBFStatus_OPEN_FILE_ERROR, + DBFStatus_NO_SUCH_FIELD_ERROR, + DBFStatus_NO_DBFVALUES_CORRESPONDENCE_WARNING + }; + + HYDROData_LandCoverMap(); + ~HYDROData_LandCoverMap(); + + DBFStatus ImportDBF( const QString& theDBFFileName, + const QString& theFieldName, + const QStringList& DBFValues, + const QStringList& StricklerTypes, + const QList& theIndices ); + + void ExportDBF( const QString& theDBFFileName, + const QString& theFieldName, + const QStringList& theDBFValues, + const QStringList& theStricklerTypes ) const; + + bool ExportTelemac( const QString& theFileName, double theDeflection ) const; + + bool Add( HYDROData_Object theObject, const QString& theType ) + [bool ( const Handle_HYDROData_Object&, const QString& )]; + %MethodCode + Handle(HYDROData_Object) aRef = + Handle(HYDROData_Object)::DownCast( createHandle( a0 ) ); + if ( !aRef.IsNull() ) + { + Py_BEGIN_ALLOW_THREADS + sipRes = sipSelfWasArg ? sipCpp->HYDROData_LandCoverMap::Add( aRef, *a1 ): + sipCpp->Add( aRef, *a1 ); + Py_END_ALLOW_THREADS + } + %End + + bool Add( HYDROData_PolylineXY thePolyline, const QString& theType ) + [bool ( const Handle_HYDROData_PolylineXY&, const QString& )]; + %MethodCode + Handle(HYDROData_PolylineXY) aRef = + Handle(HYDROData_PolylineXY)::DownCast( createHandle( a0 ) ); + if ( !aRef.IsNull() ) + { + Py_BEGIN_ALLOW_THREADS + sipRes = sipSelfWasArg ? sipCpp->HYDROData_LandCoverMap::Add( aRef, *a1 ): + sipCpp->Add( aRef, *a1 ); + Py_END_ALLOW_THREADS + } + %End + + bool Split( HYDROData_PolylineXY thePolyline ) + [bool ( const Handle_HYDROData_PolylineXY& )]; + %MethodCode + Handle(HYDROData_PolylineXY) aRef = + Handle(HYDROData_PolylineXY)::DownCast( createHandle( a0 ) ); + if ( !aRef.IsNull() ) + { + Py_BEGIN_ALLOW_THREADS + sipRes = sipSelfWasArg ? sipCpp->HYDROData_LandCoverMap::Split( aRef ): + sipCpp->Split( aRef ); + Py_END_ALLOW_THREADS + } + %End +}; diff --git a/src/HYDROPy/HYDROData_Zone.sip b/src/HYDROPy/HYDROData_Zone.sip index 31e1dd2c..070354cd 100644 --- a/src/HYDROPy/HYDROData_Zone.sip +++ b/src/HYDROPy/HYDROData_Zone.sip @@ -52,25 +52,12 @@ public: public: - /** - * Sets the merging type for conflict altitudes. - * By default it is set to Merge_ZMIN. - */ void SetMergeType( const MergeType& theType ); - - /** - * Returns the merging type for conflict altitudes. - */ MergeType GetMergeType() const; - - /** - * Sets the reference altitude to resolve the conflict. - * This object is used only in case of "Merge_Object" merge type. - */ - void SetMergeAltitude( HYDROData_IAltitudeObject theAltitude ) [void (const Handle_HYDROData_IAltitudeObject&)]; + void SetMergeAltitude( HYDROData_IAltitudeObject theAltitude ) + [void (const Handle_HYDROData_IAltitudeObject&)]; %MethodCode - Handle(HYDROData_IAltitudeObject) aRefAltitude = Handle(HYDROData_IAltitudeObject)::DownCast( createHandle( a0 ) ); if ( !aRefAltitude.IsNull() ) @@ -80,47 +67,29 @@ public: sipCpp->SetMergeObject( aRefAltitude ); Py_END_ALLOW_THREADS } - %End - /** - * Returns the reference altitude to resolve the conflict. - */ HYDROData_IAltitudeObject GetMergeAltitude() const [Handle_HYDROData_IAltitudeObject ()]; %MethodCode - Handle(HYDROData_IAltitudeObject) aRefAltitude; - Py_BEGIN_ALLOW_THREADS Handle(HYDROData_Entity) aRefObject = sipSelfWasArg ? sipCpp->HYDROData_Zone::GetMergeObject() : sipCpp->GetMergeObject(); aRefAltitude = Handle(HYDROData_IAltitudeObject)::DownCast( aRefObject ); Py_END_ALLOW_THREADS - sipRes = (HYDROData_IAltitudeObject*)createPointer( aRefAltitude ); - %End - /** - * Removes the reference altitude for resolving the conflict. - */ void RemoveMergeAltitude(); %MethodCode - Py_BEGIN_ALLOW_THREADS sipSelfWasArg ? sipCpp->HYDROData_Zone::RemoveMergeObject() : sipCpp->RemoveMergeObject(); Py_END_ALLOW_THREADS - %End - /** - * Sets the reference object to resolve the conflict. - * This object is used only in case of "Merge_Object" merge type. - */ void SetMergeObject( HYDROData_Entity theObject ) [void (const Handle_HYDROData_Entity&)]; %MethodCode - Handle(HYDROData_Entity) aRefObject = Handle(HYDROData_Entity)::DownCast( createHandle( a0 ) ); if ( !aRefObject.IsNull() ) @@ -130,34 +99,20 @@ public: sipCpp->SetMergeObject( aRefObject ); Py_END_ALLOW_THREADS } - %End - /** - * Returns the reference object to resolve the conflict. - */ HYDROData_Entity GetMergeObject() const [Handle_HYDROData_Entity ()]; %MethodCode - Handle(HYDROData_Entity) aRefObject; - Py_BEGIN_ALLOW_THREADS aRefObject = sipSelfWasArg ? sipCpp->HYDROData_Zone::GetMergeObject() : sipCpp->GetMergeObject(); Py_END_ALLOW_THREADS - sipRes = (HYDROData_Entity*)createPointer( aRefObject ); - %End - /** - * Removes the reference object for resolving the conflict. - */ void RemoveMergeObject(); - /** - * Add new one object for zone. - */ void AddObject( HYDROData_Entity theObject ) [void (const Handle_HYDROData_Entity&)]; %MethodCode @@ -173,42 +128,14 @@ public: %End - /** - * Returns all objects of zone. - */ HYDROData_SequenceOfObjects GetObjects() const; - /** - * Removes all objects from zone. - */ void RemoveObjects(); - - - /** - * Sets the interpolator for zone. By default it is NULL and original - * interpolation algorithms are used to calculate points altitudes. - * If you set interpolator it won't be stored in the data model structure, - * it will be deleted during that time as this zone will be freed. - */ void SetInterpolator( HYDROData_IInterpolator* theInter ); - - /** - * * Returns the interpolator of zone object. - */ HYDROData_IInterpolator* GetInterpolator() const; protected: - /** - * Creates new object in the internal data structure. Use higher level objects - * to create objects with real content. - */ HYDROData_Zone(); - - /** - * Destructs properties of the object and object itself, removes it from the document. - */ ~HYDROData_Zone(); }; - - diff --git a/src/HYDRO_tests/CMakeLists.txt b/src/HYDRO_tests/CMakeLists.txt index feb497da..167285a9 100644 --- a/src/HYDRO_tests/CMakeLists.txt +++ b/src/HYDRO_tests/CMakeLists.txt @@ -3,6 +3,7 @@ include(ExternalFiles.cmake) set(PROJECT_HEADERS test_HYDROData_Bathymetry.h + test_HYDROData_Channel.h test_HYDROData_Document.h test_HYDROData_Entity.h test_HYDROData_Image.h @@ -16,6 +17,7 @@ set(PROJECT_HEADERS test_HYDROGUI_ListModel.h test_Dependencies.h + TestShape.h TestViewer.h TestLib_Listener.h TestLib_Runner.h @@ -23,6 +25,7 @@ set(PROJECT_HEADERS set(PROJECT_SOURCES test_HYDROData_Bathymetry.cxx + test_HYDROData_Channel.cxx test_HYDROData_Document.cxx test_HYDROData_Entity.cxx test_HYDROData_Image.cxx @@ -37,6 +40,7 @@ set(PROJECT_SOURCES test_HYDROGUI_ListModel.cxx test_Dependencies.cxx + TestShape.cxx TestViewer.cxx TestLib_Listener.cxx TestLib_Runner.cxx @@ -55,6 +59,7 @@ SET( CPPUNIT_INCLUDES $ENV{CPPUNIT_ROOT_DIR}/include ) SET( CAS_INCLUDES $ENV{CAS_ROOT_DIR}/inc ) SET( QT_INCLUDES $ENV{QT4_ROOT_DIR}/include $ENV{QT4_ROOT_DIR}/include/QtCore $ENV{QT4_ROOT_DIR}/include/QtGui $ENV{QT4_ROOT_DIR}/include/QtTest ) SET( GUI_INCLUDES $ENV{GUI_ROOT_DIR}/include/salome ) +SET( GEOM_INCLUDES $ENV{GEOM_ROOT_DIR}/include/salome ) IF( ${WIN32} ) link_directories( $ENV{CAS_ROOT_DIR}/win32/libd ) @@ -77,15 +82,17 @@ ELSE() SET( CPPUNIT_LIBRARIES cppunit ) ENDIF() -link_directories( $ENV{GUI_ROOT_DIR}/lib/salome ) +link_directories( $ENV{GUI_ROOT_DIR}/lib/salome $ENV{GEOM_ROOT_DIR}/lib/salome ) SET( GUI_LIBRARIES ImageComposer qtx suit LightApp CAM OCCViewer ) +SET( GEOM_LIBRARIES CurveCreator ) include_directories( ${BOOST_INCLUDES} - ${CAS_INCLUDE_DIRS} + ${CAS_INCLUDES} ${QT_INCLUDES} ${CPPUNIT_INCLUDES} ${GUI_INCLUDES} + ${GEOM_INCLUDES} ${CMAKE_CURRENT_SOURCE_DIR}/../HYDROData ${CMAKE_CURRENT_SOURCE_DIR}/../HYDROGUI ${CMAKE_CURRENT_SOURCE_DIR}/../shapelib @@ -94,7 +101,7 @@ include_directories( source_group( "External files" FILES ${EXTERNAL_FILES} ) add_executable( HYDROData_tests ${PROJECT_SOURCES} ${PROJECT_HEADERS} ${EXTERNAL_FILES} ) -target_link_libraries( HYDROData_tests ${GUI_LIBRARIES} ${CAS_LIBRARIES} ${QT_LIBRARIES} ${CPPUNIT_LIBRARIES} shapelib ) +target_link_libraries( HYDROData_tests ${GUI_LIBRARIES} ${GEOM_LIBRARIES} ${CAS_LIBRARIES} ${QT_LIBRARIES} ${CPPUNIT_LIBRARIES} shapelib ) IF( ${WIN32} ) add_custom_command( TARGET HYDROData_tests POST_BUILD COMMAND $(TargetPath) COMMENT "Running tests" ) diff --git a/src/HYDRO_tests/ExternalFiles.cmake b/src/HYDRO_tests/ExternalFiles.cmake index 663cd087..7ccb5c26 100644 --- a/src/HYDRO_tests/ExternalFiles.cmake +++ b/src/HYDRO_tests/ExternalFiles.cmake @@ -56,4 +56,5 @@ set( EXTERNAL_FILES ../HYDROGUI/HYDROGUI_ListModel.cxx ../HYDROGUI/HYDROGUI_DataObject.cxx ../HYDROGUI/HYDROGUI_LandCoverMapPrs.cxx + ../HYDROGUI/HYDROGUI_Polyline.cxx ) diff --git a/src/HYDRO_tests/TestShape.cxx b/src/HYDRO_tests/TestShape.cxx new file mode 100644 index 00000000..1054ead9 --- /dev/null +++ b/src/HYDRO_tests/TestShape.cxx @@ -0,0 +1,51 @@ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +TopoDS_Edge Edge( const QList& theXYList, bool isClosed ) +{ + int n = theXYList.size()/2; + Handle(TColgp_HArray1OfPnt) aPointsArray = new TColgp_HArray1OfPnt( 1, n ); + for( int i=1; i<=n; i++ ) + { + double x = theXYList[2*i-2]; + double y = theXYList[2*i-1]; + gp_Pnt aPnt( x, y, 0 ); + aPointsArray->SetValue( i, aPnt ); + } + GeomAPI_Interpolate anInterpolator( aPointsArray, isClosed, 1E-3 ); + anInterpolator.Perform(); + bool aResult = anInterpolator.IsDone() == Standard_True; + if( aResult ) + { + Handle( Geom_BSplineCurve ) aCurve = anInterpolator.Curve(); + return BRepBuilderAPI_MakeEdge( aCurve ).Edge(); + } + else + return TopoDS_Edge(); +} + +TopoDS_Wire Wire( const QList& theXYList, bool isClosed ) +{ + return BRepBuilderAPI_MakeWire( Edge( theXYList, isClosed ) ).Wire(); +} + +TopoDS_Face Face( const QList& theXYList ) +{ + return BRepBuilderAPI_MakeFace( Wire( theXYList, true ), Standard_True ).Face(); +} + +TopoDS_Wire WireCirc( const gp_Pnt& theCenter, double theRadius ) +{ + gp_Circ aCircle( gp_Ax2( theCenter, gp_Dir( 0, 0, 1 ) ), theRadius ); + TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge( aCircle ).Edge(); + return BRepBuilderAPI_MakeWire( anEdge ).Wire(); +} diff --git a/src/HYDRO_tests/TestShape.h b/src/HYDRO_tests/TestShape.h new file mode 100644 index 00000000..17acf618 --- /dev/null +++ b/src/HYDRO_tests/TestShape.h @@ -0,0 +1,15 @@ + +#pragma once + +#include + +class TopoDS_Edge; +class TopoDS_Wire; +class TopoDS_Face; +class gp_Pnt; + +TopoDS_Edge Edge( const QList& theXYList, bool isClosed = false ); +TopoDS_Wire Wire( const QList& theXYList, bool isClosed = false ); +TopoDS_Wire WireCirc( const gp_Pnt& theCenter, double theRadius ); +TopoDS_Face Face( const QList& theXYList ); + diff --git a/src/HYDRO_tests/TestViewer.cxx b/src/HYDRO_tests/TestViewer.cxx index f54fdfc0..8315d811 100644 --- a/src/HYDRO_tests/TestViewer.cxx +++ b/src/HYDRO_tests/TestViewer.cxx @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -88,17 +89,21 @@ QColor TestViewer::GetColor(int i) void TestViewer::show( const Handle(AIS_InteractiveObject)& theObject, int theMode, int theSelectionMode, bool isFitAll, const char* theKey ) { - context()->CloseLocalContext(); - context()->EraseAll( Standard_False ); + QString aNewKey = theKey; + if( !aNewKey.isEmpty() ) + { + myKey = aNewKey; + context()->CloseLocalContext(); + context()->EraseAll( Standard_False ); + } + + context()->Display( theObject, theMode, theSelectionMode ); if( theSelectionMode > 0 ) { - context()->Display( theObject, theMode, theSelectionMode ); context()->OpenLocalContext(); context()->Activate( theObject, theSelectionMode, Standard_True ); } - myKey = theKey; - if( isFitAll ) { viewWindow()->onTopView(); @@ -109,6 +114,8 @@ void TestViewer::show( const Handle(AIS_InteractiveObject)& theObject, void TestViewer::show( const TopoDS_Shape& theShape, int theMode, bool isFitAll, const QColor& theColor ) { Handle(AIS_Shape) aShape = new AIS_Shape( theShape ); + if( theShape.ShapeType()==TopAbs_VERTEX ) + aShape->Attributes()->PointAspect()->SetTypeOfMarker( Aspect_TOM_X ); aShape->SetMaterial( Graphic3d_NOM_PLASTIC ); aShape->SetColor( HYDROData_Tool::toOccColor( theColor ) ); context()->Display( aShape, theMode, 0, Standard_False ); @@ -122,9 +129,14 @@ void TestViewer::show( const TopoDS_Shape& theShape, int theMode, bool isFitAll, void TestViewer::show( const TopoDS_Shape& theShape, int theMode, bool isFitAll, const char* theKey ) { + context()->CloseLocalContext(); context()->EraseAll( Standard_False ); myKey = theKey; + + if( theShape.IsNull() ) + return; + int i = 0; if( theShape.ShapeType()==TopAbs_SHELL ) { @@ -235,3 +247,10 @@ Handle_Aspect_ColorScale TestViewer::showColorScale( bool isShow ) } return aColorScale; } + +void TestViewer::select( int theViewX, int theViewY ) +{ + Handle(V3d_View) aView = myViewWindow->getViewPort()->getView(); + context()->MoveTo( theViewX, theViewY, aView ); + context()->Select(); +} diff --git a/src/HYDRO_tests/TestViewer.h b/src/HYDRO_tests/TestViewer.h index 61f0d6bb..d5bd15d6 100644 --- a/src/HYDRO_tests/TestViewer.h +++ b/src/HYDRO_tests/TestViewer.h @@ -26,6 +26,8 @@ public: static Handle_Aspect_ColorScale showColorScale( bool ); + static void select( int theViewX, int theViewY ); + private: static OCCViewer_ViewManager* myViewManager; static OCCViewer_ViewWindow* myViewWindow; diff --git a/src/HYDRO_tests/reference_data/Channel.png b/src/HYDRO_tests/reference_data/Channel.png new file mode 100644 index 00000000..f30b4949 Binary files /dev/null and b/src/HYDRO_tests/reference_data/Channel.png differ diff --git a/src/HYDRO_tests/reference_data/Extraction_Channel.png b/src/HYDRO_tests/reference_data/Extraction_Channel.png new file mode 100644 index 00000000..f30b4949 Binary files /dev/null and b/src/HYDRO_tests/reference_data/Extraction_Channel.png differ diff --git a/src/HYDRO_tests/reference_data/Extraction_ImmZone.png b/src/HYDRO_tests/reference_data/Extraction_ImmZone.png new file mode 100644 index 00000000..9e919787 Binary files /dev/null and b/src/HYDRO_tests/reference_data/Extraction_ImmZone.png differ diff --git a/src/HYDRO_tests/reference_data/LandCoverMap_PrsByTypes.png b/src/HYDRO_tests/reference_data/LandCoverMap_PrsByTypes.png index 218a6216..2d7da92e 100644 Binary files a/src/HYDRO_tests/reference_data/LandCoverMap_PrsByTypes.png and b/src/HYDRO_tests/reference_data/LandCoverMap_PrsByTypes.png differ diff --git a/src/HYDRO_tests/reference_data/LandCoverMap_Split_Polyline.png b/src/HYDRO_tests/reference_data/LandCoverMap_Split_Polyline.png new file mode 100644 index 00000000..98c5e924 Binary files /dev/null and b/src/HYDRO_tests/reference_data/LandCoverMap_Split_Polyline.png differ diff --git a/src/HYDRO_tests/reference_data/LandCoverMap_TransparentPrs.png b/src/HYDRO_tests/reference_data/LandCoverMap_TransparentPrs.png new file mode 100644 index 00000000..f0723e17 Binary files /dev/null and b/src/HYDRO_tests/reference_data/LandCoverMap_TransparentPrs.png differ diff --git a/src/HYDRO_tests/reference_data/Polyline_Presentation.png b/src/HYDRO_tests/reference_data/Polyline_Presentation.png new file mode 100644 index 00000000..acbf8663 Binary files /dev/null and b/src/HYDRO_tests/reference_data/Polyline_Presentation.png differ diff --git a/src/HYDRO_tests/reference_data/Split_Polylines_Colors.png b/src/HYDRO_tests/reference_data/Split_Polylines_Colors.png new file mode 100644 index 00000000..2ec01c5a Binary files /dev/null and b/src/HYDRO_tests/reference_data/Split_Polylines_Colors.png differ diff --git a/src/HYDRO_tests/test_HYDROData_Channel.cxx b/src/HYDRO_tests/test_HYDROData_Channel.cxx new file mode 100644 index 00000000..82ca4336 --- /dev/null +++ b/src/HYDRO_tests/test_HYDROData_Channel.cxx @@ -0,0 +1,84 @@ +// Copyright (C) 2014-2015 EDF-R&D +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include + +TopoDS_Edge Spline( const QList& theXYList, bool isClosed = false ); + +void test_HYDROData_Channel::test_2d_prs() +{ + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); + + Handle(HYDROData_PolylineXY) aPolyline2d = + Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) ); + aPolyline2d->SetName( "polyline2d_1" ); + aPolyline2d->AddSection( "", HYDROData_IPolyline::SECTION_SPLINE, false ); + + Handle(HYDROData_Polyline3D) aPolyline3d = + Handle(HYDROData_Polyline3D)::DownCast( aDoc->CreateObject( KIND_POLYLINE ) ); + aPolyline3d->SetName( "polyline3d_1" ); + aPolyline3d->SetPolylineXY( aPolyline2d ); + + QList aCoords = QList() << 10 << 10 << 20 << 10 << 20 << 20 << 10 << 20; + TopoDS_Wire aWire = Wire( aCoords, false ); + aPolyline2d->SetShape( aWire ); + aPolyline3d->SetTopShape( aWire ); + aPolyline3d->SetShape3D( aWire ); + + Handle(HYDROData_Profile) aProfile = + Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) ); + aProfile->SetName( "profile_1" ); + + QList aCoordsPr = QList() << 0.0 << 0.1 << 0.5 << 0.0 << 1.0 << 0.1; + TopoDS_Wire aWirePr = Wire( aCoordsPr, false ); + aProfile->SetTopShape( aWirePr ); + aProfile->SetShape3D( aWirePr ); + + + Handle(HYDROData_Channel) aChannel = + Handle(HYDROData_Channel)::DownCast( aDoc->CreateObject( KIND_CHANNEL ) ); + aChannel->SetName( "channel_1" ); + + aChannel->SetGuideLine( aPolyline3d ); + aChannel->SetProfile( aProfile ); + aChannel->Update(); + CPPUNIT_ASSERT_EQUAL( false, (bool)aChannel->GetTopShape().IsNull() ); + CPPUNIT_ASSERT_EQUAL( false, (bool)aChannel->GetShape3D().IsNull() ); + + TestViewer::show( aChannel->GetTopShape(), AIS_Shaded, true, "Channel" ); + TestViewer::show( aChannel->GetLeftShape(), AIS_WireFrame, true, Qt::red ); + TestViewer::show( aChannel->GetRightShape(), AIS_WireFrame, true, Qt::red ); + //TestViewer::show( aWire, AIS_Shaded, true, "Channel" ); + CPPUNIT_ASSERT_IMAGES + + aDoc->Close(); +} diff --git a/src/HYDRO_tests/test_HYDROData_Channel.h b/src/HYDRO_tests/test_HYDROData_Channel.h new file mode 100644 index 00000000..c4e22a89 --- /dev/null +++ b/src/HYDRO_tests/test_HYDROData_Channel.h @@ -0,0 +1,33 @@ +// Copyright (C) 2014-2015 EDF-R&D +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include + +class test_HYDROData_Channel : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE( test_HYDROData_Channel ); + CPPUNIT_TEST( test_2d_prs ); + CPPUNIT_TEST_SUITE_END(); + +private: + +public: + void test_2d_prs(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION( test_HYDROData_Channel ); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( test_HYDROData_Channel, "HYDROData_Channel"); diff --git a/src/HYDRO_tests/test_HYDROData_LandCoverMap.cxx b/src/HYDRO_tests/test_HYDROData_LandCoverMap.cxx index 5726f296..1ae4bd40 100644 --- a/src/HYDRO_tests/test_HYDROData_LandCoverMap.cxx +++ b/src/HYDRO_tests/test_HYDROData_LandCoverMap.cxx @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -26,57 +27,20 @@ #include #include #include -#include -#include -#include -#include -#include #include +#include #include #include #include #include #include #include +#include #include #include const QString REF_DATA_PATH = qgetenv( "HYDRO_REFERENCE_DATA" ); -const QString DEF_STR_PATH = qgetenv( "HYDRO_ROOT_DIR" ) + "/share/salome/resources/hydro/def_strickler_table.txt"; - -TopoDS_Edge Spline( const QList& theXYList, bool isClosed = false ) -{ - int n = theXYList.size()/2; - Handle(TColgp_HArray1OfPnt) aPointsArray = new TColgp_HArray1OfPnt( 1, n ); - for( int i=1; i<=n; i++ ) - { - double x = theXYList[2*i-2]; - double y = theXYList[2*i-1]; - gp_Pnt aPnt( x, y, 0 ); - aPointsArray->SetValue( i, aPnt ); - } - GeomAPI_Interpolate anInterpolator( aPointsArray, isClosed, 1E-3 ); - anInterpolator.Perform(); - bool aResult = anInterpolator.IsDone() == Standard_True; - if( aResult ) - { - Handle( Geom_BSplineCurve ) aCurve = anInterpolator.Curve(); - return BRepBuilderAPI_MakeEdge( aCurve ).Edge(); - } - else - return TopoDS_Edge(); -} - -TopoDS_Face LandCover( const QList& theXYList ) -{ - TopoDS_Edge anEdge = Spline( theXYList, true ); - if( anEdge.IsNull() ) - return TopoDS_Face(); - - TopoDS_Wire aWire = BRepBuilderAPI_MakeWire( anEdge ).Wire(); - TopoDS_Face aFace = BRepBuilderAPI_MakeFace( aWire, Standard_True ).Face(); - return aFace; -} +const QString DEF_STR_PATH = qgetenv( "HYDRO_SRC_DIR" ) + "/src/HYDROGUI/resources/def_strickler_table.txt"; void test_HYDROData_LandCoverMap::test_add_2_objects() { @@ -87,10 +51,10 @@ void test_HYDROData_LandCoverMap::test_add_2_objects() CPPUNIT_ASSERT_EQUAL( KIND_LAND_COVER_MAP, aMap->GetKind() ); - TopoDS_Face aLC1 = LandCover( QList() << 10 << 10 << 50 << 20 << 30 << 50 << 15 << 30 ); + TopoDS_Face aLC1 = Face( QList() << 10 << 10 << 50 << 20 << 30 << 50 << 15 << 30 ); CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC1, "test1" ) ); - TopoDS_Face aLC2 = LandCover( QList() << 30 << 20 << 60 << 10 << 70 << 35 << 40 << 40 ); + TopoDS_Face aLC2 = Face( QList() << 30 << 20 << 60 << 10 << 70 << 35 << 40 << 40 ); CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC2, "test2" ) ); TestViewer::show( aMap->GetShape(), AIS_Shaded, true, "LandCoverMap_Add_2_Objects" ); @@ -117,12 +81,12 @@ void test_HYDROData_LandCoverMap::test_split() CPPUNIT_ASSERT_EQUAL( KIND_LAND_COVER_MAP, aMap->GetKind() ); - TopoDS_Face aLC = LandCover( QList() << 10 << 10 << 50 << 20 << 30 << 50 << 15 << 30 ); + TopoDS_Face aLC = Face( QList() << 10 << 10 << 50 << 20 << 30 << 50 << 15 << 30 ); CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC, "test1" ) ); Handle(HYDROData_PolylineXY) aPolyline = Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) ); - TopoDS_Wire aWire = BRepBuilderAPI_MakeWire( Spline( QList() << 10 << 40 << 30 << 10 << 40 << 10 << 60 << 10 ) ).Wire(); + TopoDS_Wire aWire = Wire( QList() << 10 << 40 << 30 << 10 << 40 << 10 << 60 << 10, false ); aPolyline->SetShape( aWire ); CPPUNIT_ASSERT_EQUAL( true, aMap->Split( aPolyline ) ); @@ -152,12 +116,12 @@ void test_HYDROData_LandCoverMap::test_incomplete_split() CPPUNIT_ASSERT_EQUAL( KIND_LAND_COVER_MAP, aMap->GetKind() ); - TopoDS_Face aLC = LandCover( QList() << 10 << 10 << 50 << 20 << 30 << 50 << 15 << 30 ); + TopoDS_Face aLC = Face( QList() << 10 << 10 << 50 << 20 << 30 << 50 << 15 << 30 ); CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC, "test1" ) ); Handle(HYDROData_PolylineXY) aPolyline = Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) ); - TopoDS_Wire aWire = BRepBuilderAPI_MakeWire( Spline( QList() << 10 << 40 << 30 << 10 << 40 << 10 ) ).Wire(); + TopoDS_Wire aWire = Wire( QList() << 10 << 40 << 30 << 10 << 40 << 10, false ); aPolyline->SetShape( aWire ); CPPUNIT_ASSERT_EQUAL( true, aMap->Split( aPolyline ) ); @@ -184,18 +148,18 @@ void test_HYDROData_LandCoverMap::test_merge() CPPUNIT_ASSERT_EQUAL( KIND_LAND_COVER_MAP, aMap->GetKind() ); - TopoDS_Face aLC1 = LandCover( QList() << 12 << 19 << 82 << 9 << 126 << 53 << 107 << 80 << 29 << 75 ); + TopoDS_Face aLC1 = Face( QList() << 12 << 19 << 82 << 9 << 126 << 53 << 107 << 80 << 29 << 75 ); CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC1, "test1" ) ); - TopoDS_Face aLC2 = LandCover( QList() << 21 << 34 << 24 << 25 << 37 << 37 << 40 << 61 << - 44 << 95 << 85 << 100 << 104 << 66 << 107 << 33 << - 128 << 18 << 140 << 50 << 131 << 89 << 104 << 111 << - 31 << 114 ); + TopoDS_Face aLC2 = Face( QList() << 21 << 34 << 24 << 25 << 37 << 37 << 40 << 61 << + 44 << 95 << 85 << 100 << 104 << 66 << 107 << 33 << + 128 << 18 << 140 << 50 << 131 << 89 << 104 << 111 << + 31 << 114 ); CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC2, "test2" ) ); - TopoDS_Face aLC3 = LandCover( QList() << 4 << 54 << 1 << 47 << 51 << 45 << - 127 << 42 << 145 << 43 << 148 << 60 << 90 << 65 ); + TopoDS_Face aLC3 = Face( QList() << 4 << 54 << 1 << 47 << 51 << 45 << + 127 << 42 << 145 << 43 << 148 << 60 << 90 << 65 ); CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC3, "test3" ) ); //TestViewer::show( aMap->GetShape(), AIS_Shaded, true ); @@ -229,18 +193,18 @@ void test_HYDROData_LandCoverMap::test_remove() CPPUNIT_ASSERT_EQUAL( KIND_LAND_COVER_MAP, aMap->GetKind() ); - TopoDS_Face aLC1 = LandCover( QList() << 12 << 19 << 82 << 9 << 126 << 53 << 107 << 80 << 29 << 75 ); + TopoDS_Face aLC1 = Face( QList() << 12 << 19 << 82 << 9 << 126 << 53 << 107 << 80 << 29 << 75 ); CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC1, "test1" ) ); - TopoDS_Face aLC2 = LandCover( QList() << 21 << 34 << 24 << 25 << 37 << 37 << 40 << 61 << - 44 << 95 << 85 << 100 << 104 << 66 << 107 << 33 << - 128 << 18 << 140 << 50 << 131 << 89 << 104 << 111 << - 31 << 114 ); + TopoDS_Face aLC2 = Face( QList() << 21 << 34 << 24 << 25 << 37 << 37 << 40 << 61 << + 44 << 95 << 85 << 100 << 104 << 66 << 107 << 33 << + 128 << 18 << 140 << 50 << 131 << 89 << 104 << 111 << + 31 << 114 ); CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC2, "test2" ) ); - TopoDS_Face aLC3 = LandCover( QList() << 4 << 54 << 1 << 47 << 51 << 45 << - 127 << 42 << 145 << 43 << 148 << 60 << 90 << 65 ); + TopoDS_Face aLC3 = Face( QList() << 4 << 54 << 1 << 47 << 51 << 45 << + 127 << 42 << 145 << 43 << 148 << 60 << 90 << 65 ); CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC3, "test3" ) ); QString aType1, aType2; @@ -471,25 +435,21 @@ void test_HYDROData_LandCoverMap::test_import_dbf() // aST.size() == aDBFV.size()!! Handle(HYDROData_PolylineXY) aPolyline = Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) ); - TopoDS_Wire aWire = BRepBuilderAPI_MakeWire( Spline( QList() << 10 << 40 << 30 << 10 << 40 << 10 << 60 << 10 ) ).Wire(); + TopoDS_Wire aWire = Wire( QList() << 10 << 40 << 30 << 10 << 40 << 10 << 60 << 10 ); aPolyline->SetShape( aWire ); for (int i = 0; i < 3; i++) aMap->Add(aPolyline, ""); - TopoDS_Face aLC1 = LandCover( QList() << 10 << 10 << 50 << 20 << 30 << 50 << 15 << 30 ); + TopoDS_Face aLC1 = Face( QList() << 10 << 10 << 50 << 20 << 30 << 50 << 15 << 30 ); CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC1, "test1" ) ); CPPUNIT_ASSERT_EQUAL( true, aMap->Split( aPolyline ) ); - QMap Inds; - Inds.insert(1, 1); - Inds.insert(2, 2); - Inds.insert(3, 3); + QList Inds = QList() << 1 << 2 << 3; aMap->ImportDBF(aFileName, "TESTFIELD1", aDBFV, aST, Inds); HYDROData_LandCoverMap::Iterator anIt( aMap ); - CPPUNIT_ASSERT_EQUAL(true, "water" == anIt.StricklerType()); + CPPUNIT_ASSERT_EQUAL( QString( "forest" ), anIt.StricklerType() ); anIt.Next(); - CPPUNIT_ASSERT_EQUAL(true, "forest" == anIt.StricklerType()); - + CPPUNIT_ASSERT_EQUAL( QString( "road" ), anIt.StricklerType() ); } void test_HYDROData_LandCoverMap::test_land_cover_prs_by_types() @@ -503,22 +463,26 @@ void test_HYDROData_LandCoverMap::test_land_cover_prs_by_types() Handle(HYDROData_LandCoverMap) aMap = Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) ); - TopoDS_Face aLC1 = LandCover( QList() << 12 << 19 << 82 << 9 << 126 << 53 << 107 << 80 << 29 << 75 ); + TopoDS_Face aLC1 = Face( QList() << 12 << 19 << 82 << 9 << 126 << 53 << 107 << 80 << 29 << 75 ); CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC1, "Zones de champs cultivé à végétation basse" ) ); - TopoDS_Face aLC2 = LandCover( QList() << 21 << 34 << 24 << 25 << 37 << 37 << 40 << 61 << - 44 << 95 << 85 << 100 << 104 << 66 << 107 << 33 << - 128 << 18 << 140 << 50 << 131 << 89 << 104 << 111 << - 31 << 114 ); + TopoDS_Face aLC2 = Face( QList() << 21 << 34 << 24 << 25 << 37 << 37 << 40 << 61 << + 44 << 95 << 85 << 100 << 104 << 66 << 107 << 33 << + 128 << 18 << 140 << 50 << 131 << 89 << 104 << 111 << + 31 << 114 ); CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC2, "Zones de champs cultivé à végétation haute" ) ); - TopoDS_Face aLC3 = LandCover( QList() << 4 << 54 << 1 << 47 << 51 << 45 << - 127 << 42 << 145 << 43 << 148 << 60 << 90 << 65 ); + TopoDS_Face aLC3 = Face( QList() << 4 << 54 << 1 << 47 << 51 << 45 << + 127 << 42 << 145 << 43 << 148 << 60 << 90 << 65 ); CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC3, "Zones de champs, prairies, sans cultures" ) ); + // build presentation object Handle(HYDROGUI_LandCoverMapPrs) aPrs = new HYDROGUI_LandCoverMapPrs( aMap ); aPrs->SetTable( aTable ); + // show presentation in viewer TestViewer::show( aPrs, AIS_Shaded, 4, true, "LandCoverMap_PrsByTypes" ); + // select one of faces (first) + TestViewer::select( 200, 300 ); CPPUNIT_ASSERT_IMAGES aDoc->Close(); @@ -535,17 +499,17 @@ void test_HYDROData_LandCoverMap::test_land_cover_prs_by_coeff() Handle(HYDROData_LandCoverMap) aMap = Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) ); - TopoDS_Face aLC1 = LandCover( QList() << 12 << 19 << 82 << 9 << 126 << 53 << 107 << 80 << 29 << 75 ); + TopoDS_Face aLC1 = Face( QList() << 12 << 19 << 82 << 9 << 126 << 53 << 107 << 80 << 29 << 75 ); CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC1, "Zones de champs cultivé à végétation basse" ) ); - TopoDS_Face aLC2 = LandCover( QList() << 21 << 34 << 24 << 25 << 37 << 37 << 40 << 61 << - 44 << 95 << 85 << 100 << 104 << 66 << 107 << 33 << - 128 << 18 << 140 << 50 << 131 << 89 << 104 << 111 << - 31 << 114 ); + TopoDS_Face aLC2 = Face( QList() << 21 << 34 << 24 << 25 << 37 << 37 << 40 << 61 << + 44 << 95 << 85 << 100 << 104 << 66 << 107 << 33 << + 128 << 18 << 140 << 50 << 131 << 89 << 104 << 111 << + 31 << 114 ); CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC2, "Zones de champs cultivé à végétation haute" ) ); - TopoDS_Face aLC3 = LandCover( QList() << 4 << 54 << 1 << 47 << 51 << 45 << - 127 << 42 << 145 << 43 << 148 << 60 << 90 << 65 ); + TopoDS_Face aLC3 = Face( QList() << 4 << 54 << 1 << 47 << 51 << 45 << + 127 << 42 << 145 << 43 << 148 << 60 << 90 << 65 ); CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC3, "Zones de champs, prairies, sans cultures" ) ); Handle(HYDROGUI_LandCoverMapPrs) aPrs = new HYDROGUI_LandCoverMapPrs( aMap ); @@ -558,3 +522,69 @@ void test_HYDROData_LandCoverMap::test_land_cover_prs_by_coeff() aDoc->Close(); } +void test_HYDROData_LandCoverMap::test_dump_python() +{ + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); + + Handle(HYDROData_LandCoverMap) aMap = + Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) ); + aMap->SetName( "test_LCM" ); + + CPPUNIT_ASSERT_EQUAL( KIND_LAND_COVER_MAP, aMap->GetKind() ); + + TopoDS_Face aLC1 = Face( QList() << 12 << 19 << 82 << 9 << 126 << 53 << 107 << 80 << 29 << 75 ); + + CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC1, "test1" ) ); + + TopoDS_Face aLC2 = Face( QList() << 21 << 34 << 24 << 25 << 37 << 37 << 40 << 61 << + 44 << 95 << 85 << 100 << 104 << 66 << 107 << 33 << + 128 << 18 << 140 << 50 << 131 << 89 << 104 << 111 << + 31 << 114 ); + CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC2, "test2" ) ); + + TopoDS_Face aLC3 = Face( QList() << 4 << 54 << 1 << 47 << 51 << 45 << + 127 << 42 << 145 << 43 << 148 << 60 << 90 << 65 ); + CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC3, "test3" ) ); + + QString aTmpPath = QDir::tempPath() + "/lc_dump.py"; + CPPUNIT_ASSERT_EQUAL( true, aDoc->DumpToPython( aTmpPath, false ) ); + + //TODO: compare files +} + +void test_HYDROData_LandCoverMap::test_transparent_prs() +{ + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); + + Handle(HYDROData_StricklerTable) aTable = + Handle(HYDROData_StricklerTable)::DownCast( aDoc->CreateObject( KIND_STRICKLER_TABLE ) ); + CPPUNIT_ASSERT_EQUAL( true, aTable->Import( DEF_STR_PATH ) ); + + Handle(HYDROData_PolylineXY) aPoly = + Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) ); + aPoly->AddSection( "", HYDROData_PolylineXY::SECTION_SPLINE, true ); + aPoly->AddPoint( 0, gp_XY( 0, 0 ) ); + aPoly->AddPoint( 0, gp_XY( 20, 0 ) ); + aPoly->AddPoint( 0, gp_XY( 10, 10 ) ); + aPoly->Update(); + + Handle(HYDROData_ImmersibleZone) aZone = + Handle(HYDROData_ImmersibleZone)::DownCast( aDoc->CreateObject( KIND_IMMERSIBLE_ZONE ) ); + aZone->SetPolyline( aPoly ); + aZone->Update(); + + Handle(HYDROData_LandCoverMap) aMap = + Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) ); + aMap->LocalPartition( Face( QList() << 1 << 1 << 10 << 10 << 10 << 20 ), "Zones de champs cultivé à végétation haute" ); + aMap->LocalPartition( Face( QList() << 5 << 5 << 10 << 5 << 10 << 8 << 5 << 12 << 5 << 8 ), "Zones de champs cultivé à végétation haute" ); + aMap->SetName( "test_LCM" ); + + TestViewer::show( aZone->GetTopShape(), AIS_Shaded, true, "LandCoverMap_TransparentPrs" ); + + Handle(HYDROGUI_LandCoverMapPrs) aPrs = new HYDROGUI_LandCoverMapPrs( aMap ); + aPrs->SetTable( aTable ); + aPrs->SetTransparency( 0.5 ); + TestViewer::show( aPrs, AIS_Shaded, 0, true, "" ); + + CPPUNIT_ASSERT_IMAGES +} diff --git a/src/HYDRO_tests/test_HYDROData_LandCoverMap.h b/src/HYDRO_tests/test_HYDROData_LandCoverMap.h index 95ea4d4b..609a1802 100644 --- a/src/HYDRO_tests/test_HYDROData_LandCoverMap.h +++ b/src/HYDRO_tests/test_HYDROData_LandCoverMap.h @@ -35,6 +35,8 @@ class test_HYDROData_LandCoverMap : public CppUnit::TestFixture CPPUNIT_TEST( test_import_dbf ); CPPUNIT_TEST( test_land_cover_prs_by_types ); CPPUNIT_TEST( test_land_cover_prs_by_coeff ); + CPPUNIT_TEST( test_dump_python ); + CPPUNIT_TEST( test_transparent_prs ); CPPUNIT_TEST_SUITE_END(); public: @@ -48,6 +50,8 @@ public: void test_import_dbf(); void test_land_cover_prs_by_types(); void test_land_cover_prs_by_coeff(); + void test_dump_python(); + void test_transparent_prs(); }; CPPUNIT_TEST_SUITE_REGISTRATION( test_HYDROData_LandCoverMap ); diff --git a/src/HYDRO_tests/test_HYDROData_PolylineXY.cxx b/src/HYDRO_tests/test_HYDROData_PolylineXY.cxx index 95a89ee8..c44a9f5b 100644 --- a/src/HYDRO_tests/test_HYDROData_PolylineXY.cxx +++ b/src/HYDRO_tests/test_HYDROData_PolylineXY.cxx @@ -18,12 +18,33 @@ #include +#include #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include +#include +#include +#include +#include +#include +#include + void test_HYDROData_PolylineXY::testPolyline() { Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( 1 ); @@ -70,5 +91,282 @@ void test_HYDROData_PolylineXY::testCopy() aPolyline1->CopyTo(aPolyline2, true); + aDoc->Close(); +} + +void test_HYDROData_PolylineXY::testSplit_refs_624() +{ + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( 1 ); + + Handle(HYDROData_PolylineXY) aPolyline = + Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) ); + aPolyline->SetName( "test" ); + + QList aCoords = QList() << 10 << 10 << 20 << 10 << 20 << 20 << 10 << 20; + TopoDS_Wire aWire = Wire( aCoords, true ); + aPolyline->SetShape( aWire ); + + gp_Pnt2d aPnt( 20, 20 ); + + TestViewer::show( aPolyline->GetShape(), 0, true, "LandCoverMap_Split_Polyline" ); + //TestViewer::show( BRepBuilderAPI_MakeVertex( aPnt ).Vertex(), 1, true, Qt::green ); + CPPUNIT_ASSERT_IMAGES + + HYDROData_PolylineOperator anOp; + CPPUNIT_ASSERT_EQUAL( true, anOp.Split( aDoc, aPolyline, aPnt, 1E-3 ) ); + + HYDROData_Iterator anIt( aDoc, KIND_POLYLINEXY ); + CPPUNIT_ASSERT_EQUAL( true, anIt.More() ); + CPPUNIT_ASSERT_EQUAL( QString( "test" ), anIt.Current()->GetName() ); + anIt.Next(); + CPPUNIT_ASSERT_EQUAL( true, anIt.More() ); + CPPUNIT_ASSERT_EQUAL( QString( "test_1" ), anIt.Current()->GetName() ); + anIt.Next(); + CPPUNIT_ASSERT_EQUAL( false, anIt.More() ); + + aDoc->Close(); +} + +void test_HYDROData_PolylineXY::test_extraction_immersible_zone() +{ + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( 1 ); + + Handle(HYDROData_PolylineXY) aPolyline = + Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) ); + aPolyline->SetName( "test" ); + + QList aCoords = QList() << 10 << 10 << 20 << 10 << 20 << 20 << 10 << 20; + TopoDS_Wire aWire = Wire( aCoords, true ); + aPolyline->SetShape( aWire ); + + Handle(HYDROData_ImmersibleZone) aZone = + Handle(HYDROData_ImmersibleZone)::DownCast( aDoc->CreateObject( KIND_IMMERSIBLE_ZONE ) ); + aZone->SetName( "zone" ); + aZone->SetPolyline( aPolyline ); + aZone->Update(); + + CPPUNIT_ASSERT_EQUAL( false, (bool)aZone->GetTopShape().IsNull() ); + + HYDROData_PolylineOperator anOp; + CPPUNIT_ASSERT_EQUAL( true, anOp.Extract( aDoc, aZone ) ); + + Handle(HYDROData_PolylineXY) anOuter = + Handle(HYDROData_PolylineXY)::DownCast( aDoc->FindObjectByName( "zone_Outer_1", KIND_POLYLINEXY ) ); + CPPUNIT_ASSERT_EQUAL( false, (bool)anOuter.IsNull() ); + + TestViewer::show( aZone->GetTopShape(), 1, true, "Extraction_ImmZone" ); + TestViewer::show( anOuter->GetShape(), 0, true, Qt::red ); + CPPUNIT_ASSERT_IMAGES + + aDoc->Close(); +} + +void test_HYDROData_PolylineXY::test_extraction_channel_refs_611() +{ + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); + + Handle(HYDROData_PolylineXY) aPolyline2d = + Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) ); + aPolyline2d->SetName( "polyline2d_1" ); + aPolyline2d->AddSection( "", HYDROData_IPolyline::SECTION_SPLINE, false ); + + Handle(HYDROData_Polyline3D) aPolyline3d = + Handle(HYDROData_Polyline3D)::DownCast( aDoc->CreateObject( KIND_POLYLINE ) ); + aPolyline3d->SetName( "polyline3d_1" ); + aPolyline3d->SetPolylineXY( aPolyline2d ); + + QList aCoords = QList() << 10 << 10 << 20 << 10 << 20 << 20 << 10 << 20; + TopoDS_Wire aWire = Wire( aCoords, false ); + aPolyline2d->SetShape( aWire ); + aPolyline3d->SetTopShape( aWire ); + aPolyline3d->SetShape3D( aWire ); + + Handle(HYDROData_Profile) aProfile = + Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) ); + aProfile->SetName( "profile_1" ); + + QList aCoordsPr = QList() << 0.0 << 0.1 << 0.5 << 0.0 << 1.0 << 0.1; + TopoDS_Wire aWirePr = Wire( aCoordsPr, false ); + aProfile->SetTopShape( aWirePr ); + aProfile->SetShape3D( aWirePr ); + + + Handle(HYDROData_Channel) aChannel = + Handle(HYDROData_Channel)::DownCast( aDoc->CreateObject( KIND_CHANNEL ) ); + aChannel->SetName( "channel_1" ); + + aChannel->SetGuideLine( aPolyline3d ); + aChannel->SetProfile( aProfile ); + aChannel->Update(); + CPPUNIT_ASSERT_EQUAL( false, (bool)aChannel->GetTopShape().IsNull() ); + CPPUNIT_ASSERT_EQUAL( false, (bool)aChannel->GetShape3D().IsNull() ); + + HYDROData_PolylineOperator anOp; + CPPUNIT_ASSERT_EQUAL( true, anOp.Extract( aDoc, aChannel ) ); + + Handle(HYDROData_PolylineXY) aLeft = + Handle(HYDROData_PolylineXY)::DownCast( aDoc->FindObjectByName( "channel_1_Left_Bank_1", KIND_POLYLINEXY ) ); + Handle(HYDROData_PolylineXY) aRight = + Handle(HYDROData_PolylineXY)::DownCast( aDoc->FindObjectByName( "channel_1_Right_Bank_1", KIND_POLYLINEXY ) ); + CPPUNIT_ASSERT_EQUAL( false, (bool)aRight.IsNull() ); + + TestViewer::show( aChannel->GetTopShape(), 1, true, "Extraction_Channel" ); + TestViewer::show( aLeft->GetShape(), 0, true, Qt::red ); + TestViewer::show( aRight->GetShape(), 0, true, Qt::red ); + CPPUNIT_ASSERT_IMAGES + + aDoc->Close(); +} + +void test_HYDROData_PolylineXY::test_presentation() +{ + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); + + Handle(HYDROData_PolylineXY) aPolyline2d = + Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) ); + aPolyline2d->SetName( "polyline2d_1" ); + aPolyline2d->AddSection( "", HYDROData_IPolyline::SECTION_SPLINE, false ); + + QList aPoints = QList() << gp_XY( 0, 0 ) + << gp_XY( 10, 10 ) + << gp_XY( 20, 40 ) + << gp_XY( 30, 10 ) + << gp_XY( 40, 50 ) + << gp_XY( 50, 60 ) + << gp_XY( -10, 40 ) + << gp_XY( -9, 39 ) + << gp_XY( -8, 38 ) + << gp_XY( 0, 20 ); + Handle(TColgp_HArray1OfPnt) aPnts = new TColgp_HArray1OfPnt( 1, aPoints.size() ); + int i = 1; + foreach( gp_XY aPoint, aPoints ) + { + aPolyline2d->AddPoint( 0, aPoint ); + aPnts->SetValue( i, gp_Pnt( aPoint.X(), aPoint.Y(), 0 ) ); + i++; + } + aPolyline2d->Update(); + + CPPUNIT_ASSERT_EQUAL( false, (bool)aPolyline2d->GetShape().IsNull() ); + + Handle(AIS_PointCloud) aPointsPrs = new AIS_PointCloud(); + aPointsPrs->SetPoints( aPnts ); + aPointsPrs->SetColor( Quantity_NOC_BLUE1 ); + aPointsPrs->Attributes()->PointAspect()->SetTypeOfMarker( Aspect_TOM_O ); + + Handle(HYDROGUI_Polyline) aNewPolylinePrs = new HYDROGUI_Polyline( aPolyline2d->GetShape() ); + aNewPolylinePrs->SetColor( Quantity_NOC_DARKGREEN ); + + TestViewer::show( aPointsPrs, AIS_PointCloud::DM_Points, 0, true, "Polyline_Presentation" ); + TestViewer::show( aPolyline2d->GetShape(), 0, true, Qt::red ); + TestViewer::show( aNewPolylinePrs, AIS_PointCloud::DM_Points, 0, true, "" ); + CPPUNIT_ASSERT_IMAGES + + aDoc->Close(); +} + +void test_HYDROData_PolylineXY::testSplit_refs_627() +{ + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( 1 ); + + Handle(HYDROData_PolylineXY) aPolyline = + Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) ); + aPolyline->SetName( "test" ); + + QList aCoords = QList() << 10 << 10 << 20 << 10 << 20 << 20 << 10 << 20; + TopoDS_Wire aWire = Wire( aCoords, false ); + aPolyline->SetShape( aWire ); + aPolyline->SetWireColor( Qt::red ); + + gp_Pnt2d aPnt( 20, 20 ); + + HYDROData_PolylineOperator anOp; + CPPUNIT_ASSERT_EQUAL( true, anOp.Split( aDoc, aPolyline, aPnt, 1E-3 ) ); + + TestViewer::show( TopoDS_Shape(), 0, true, "Split_Polylines_Colors" ); + HYDROData_Iterator anIt( aDoc, KIND_POLYLINEXY ); + for( ; anIt.More(); anIt.Next() ) + { + Handle(HYDROData_PolylineXY) anObj = Handle(HYDROData_PolylineXY)::DownCast( anIt.Current() ); + if( aPolyline->Label() != anObj->Label() ) + TestViewer::show( anObj->GetShape(), 0, true, anObj->GetWireColor() ); + } + CPPUNIT_ASSERT_IMAGES + + HYDROData_Iterator anIt2( aDoc, KIND_POLYLINEXY ); + CPPUNIT_ASSERT_EQUAL( true, anIt2.More() ); + CPPUNIT_ASSERT_EQUAL( QString( "test" ), anIt2.Current()->GetName() ); + CPPUNIT_ASSERT_EQUAL( QColor( Qt::red ), + Handle(HYDROData_PolylineXY)::DownCast( anIt2.Current() )->GetWireColor() ); + anIt2.Next(); + CPPUNIT_ASSERT_EQUAL( true, anIt2.More() ); + CPPUNIT_ASSERT_EQUAL( QString( "test_1" ), anIt2.Current()->GetName() ); + CPPUNIT_ASSERT_EQUAL( QColor( Qt::red ), + Handle(HYDROData_PolylineXY)::DownCast( anIt2.Current() )->GetWireColor() ); + anIt2.Next(); + CPPUNIT_ASSERT_EQUAL( true, anIt2.More() ); + CPPUNIT_ASSERT_EQUAL( QString( "test_2" ), anIt2.Current()->GetName() ); + CPPUNIT_ASSERT_EQUAL( QColor( Qt::red ), + Handle(HYDROData_PolylineXY)::DownCast( anIt2.Current() )->GetWireColor() ); + anIt2.Next(); + CPPUNIT_ASSERT_EQUAL( false, anIt2.More() ); + anIt2.Next(); + + aDoc->Close(); +} + +void test_HYDROData_PolylineXY::test_custom_polylines() +{ + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( 1 ); + + Handle(HYDROData_PolylineXY) aPolyline1 = + Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) ); + Handle(HYDROData_PolylineXY) aPolyline2 = + Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) ); + Handle(HYDROData_PolylineXY) aPolyline3 = + Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) ); + + aPolyline1->SetName( "test1" ); + aPolyline2->SetName( "test2" ); + aPolyline3->SetName( "test3" ); + + CPPUNIT_ASSERT_EQUAL( false, aPolyline1->IsCustom() ); + aPolyline1->AddSection( "", HYDROData_IPolyline::SECTION_SPLINE, false ); + aPolyline1->Update(); + CPPUNIT_ASSERT_EQUAL( false, aPolyline1->IsCustom() ); + aPolyline1->AddPoint( 0, gp_XY( 0, 0 ) ); + aPolyline1->Update(); + CPPUNIT_ASSERT_EQUAL( false, aPolyline1->IsCustom() ); + + CPPUNIT_ASSERT_EQUAL( false, aPolyline2->IsCustom() ); + aPolyline2->SetShape( Wire( QList() << 0 << 0 << 1 << 1 << 2 << 0 ) ); + CPPUNIT_ASSERT_EQUAL( true, aPolyline2->IsCustom() ); + HYDROData_PolylineXY::PointsList aPointsList = aPolyline2->GetPoints( 0 ); + + CPPUNIT_ASSERT_EQUAL( false, aPolyline2->IsCustom() ); + CPPUNIT_ASSERT_EQUAL( 33, aPointsList.Size() ); + CPPUNIT_ASSERT_EQUAL( gp_XY( 0, 0 ), aPointsList.Value( 1 ) ); + CPPUNIT_ASSERT_EQUAL( gp_XY( 0.5625, 0.808594 ), aPointsList.Value( 10 ) ); + CPPUNIT_ASSERT_EQUAL( gp_XY( 1.1875, 0.964844 ), aPointsList.Value( 20 ) ); + CPPUNIT_ASSERT_EQUAL( gp_XY( 2, 0 ), aPointsList.Value( 33 ) ); + + + CPPUNIT_ASSERT_EQUAL( false, aPolyline3->IsCustom() ); + aPolyline3->SetShape( WireCirc( gp_Pnt(), 1.0 ) ); + CPPUNIT_ASSERT_EQUAL( true, aPolyline3->IsCustom() ); + aPointsList = aPolyline3->GetPoints( 0 ); + + CPPUNIT_ASSERT_EQUAL( HYDROData_PolylineXY::SECTION_SPLINE, aPolyline3->GetSectionType( 0 ) ); + CPPUNIT_ASSERT_EQUAL( true, aPolyline3->IsClosedSection( 0 ) ); + CPPUNIT_ASSERT_EQUAL( 71, aPointsList.Size() ); + CPPUNIT_ASSERT_EQUAL( gp_XY( 1, 0 ), aPointsList.Value( 1 ) ); + CPPUNIT_ASSERT_EQUAL( gp_XY( 0.699242, 0.714885 ), aPointsList.Value( 10 ) ); + CPPUNIT_ASSERT_EQUAL( gp_XY( -0.110394, 0.993888 ), aPointsList.Value( 20 ) ); + CPPUNIT_ASSERT_EQUAL( gp_XY( -0.839072, 0.54402 ), aPointsList.Value( 30 ) ); + CPPUNIT_ASSERT_EQUAL( gp_XY( -0.952415, -0.304806 ), aPointsList.Value( 40 ) ); + CPPUNIT_ASSERT_EQUAL( gp_XY( -0.367302, -0.930102 ), aPointsList.Value( 50 ) ); + CPPUNIT_ASSERT_EQUAL( gp_XY( 0.487173, -0.873306 ), aPointsList.Value( 60 ) ); + CPPUNIT_ASSERT_EQUAL( gp_XY( 0.996087, -0.0883801 ), aPointsList.Value( 71 ) ); + aDoc->Close(); } diff --git a/src/HYDRO_tests/test_HYDROData_PolylineXY.h b/src/HYDRO_tests/test_HYDROData_PolylineXY.h index 24623b3c..3a7b53bb 100644 --- a/src/HYDRO_tests/test_HYDROData_PolylineXY.h +++ b/src/HYDRO_tests/test_HYDROData_PolylineXY.h @@ -19,9 +19,15 @@ #include class test_HYDROData_PolylineXY : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(test_HYDROData_PolylineXY); - CPPUNIT_TEST(testPolyline); - CPPUNIT_TEST(testCopy); + CPPUNIT_TEST_SUITE( test_HYDROData_PolylineXY ); + CPPUNIT_TEST( testPolyline ); + CPPUNIT_TEST( testCopy ); + CPPUNIT_TEST( testSplit_refs_624 ); + CPPUNIT_TEST( testSplit_refs_627 ); + CPPUNIT_TEST( test_presentation ); + CPPUNIT_TEST( test_extraction_immersible_zone ); + CPPUNIT_TEST( test_extraction_channel_refs_611 ); + CPPUNIT_TEST( test_custom_polylines ); CPPUNIT_TEST_SUITE_END(); private: @@ -37,6 +43,14 @@ public: // checks the image properties copy/paste void testCopy(); + + void testSplit_refs_624(); + void testSplit_refs_627(); + + void test_extraction_immersible_zone(); + void test_extraction_channel_refs_611(); + void test_presentation(); + void test_custom_polylines(); }; CPPUNIT_TEST_SUITE_REGISTRATION(test_HYDROData_PolylineXY); diff --git a/src/HYDRO_tests/test_HYDROData_StricklerTable.cxx b/src/HYDRO_tests/test_HYDROData_StricklerTable.cxx index a7c2da12..05b2dc4b 100644 --- a/src/HYDRO_tests/test_HYDROData_StricklerTable.cxx +++ b/src/HYDRO_tests/test_HYDROData_StricklerTable.cxx @@ -24,7 +24,7 @@ #include #include -const QString DEF_STR_PATH = qgetenv( "HYDRO_ROOT_DIR" ) + "/share/salome/resources/hydro/def_strickler_table.txt"; +const QString DEF_STR_PATH = qgetenv( "HYDRO_SRC_DIR" ) + "/src/HYDROGUI/resources/def_strickler_table.txt"; void test_HYDROData_StricklerTable::test_import() { diff --git a/src/shapelib/CMakeLists.txt b/src/shapelib/CMakeLists.txt index 419c3c4c..2c5cf258 100644 --- a/src/shapelib/CMakeLists.txt +++ b/src/shapelib/CMakeLists.txt @@ -13,13 +13,13 @@ set(PROJECT_SOURCES ) add_definitions( - -DSHAPELIB_DLLEXPORT + -DSHAPELIB_DLLEXPORT -fPIC ) include_directories( ) -add_library(shapelib SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS}) +add_library(shapelib STATIC ${PROJECT_SOURCES} ${PROJECT_HEADERS}) INSTALL(TARGETS shapelib EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_LIBS}) set(PROJECT_LIBRARIES shapelib)