#include <HYDROData_Polyline.h>
#include <HYDROData_Iterator.h>
+#include <HYDROData_BSplineOperation.h>
+
#include <ImageComposer_MetaTypes.h>
+#include <BRepBuilderAPI_MakeEdge.hxx>
+#include <BRepBuilderAPI_MakeWire.hxx>
+#include <gp_Pnt.hxx>
#include <TDataStd_Name.hxx>
#include <TDataStd_Integer.hxx>
#include <TDataStd_ByteArray.hxx>
#include <TDataStd_BooleanArray.hxx>
#include <TDataStd_IntegerArray.hxx>
+#include <TDataStd_Real.hxx>
#include <TDataStd_RealArray.hxx>
#include <TDataStd_ExtStringArray.hxx>
#include <TDataStd_UAttribute.hxx>
#include <TDF_ListIteratorOfLabelList.hxx>
+#include <TNaming_Builder.hxx>
+#include <TNaming_NamedShape.hxx>
+#include <TopoDS.hxx>
+#include <TopoDS_Edge.hxx>
+#include <TopoDS_Wire.hxx>
#include <QStringList>
IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Polyline, HYDROData_Object)
HYDROData_Polyline::HYDROData_Polyline()
+: HYDROData_Object()
{
}
{
}
+TopoDS_Shape HYDROData_Polyline::GetTopShape() const
+{
+ // TODO
+ return getTopShape();
+}
+
+TopoDS_Shape HYDROData_Polyline::GetShape3D() const
+{
+ // TODO
+ return getTopShape();
+}
+
/**
* Dump object to Python script representation.
*/
aResList << QString( "" );
- int aDim = getDimension();
- aResList << QString( "%1.setDimension( %2 );" )
+ int aDim = GetDimension();
+ aResList << QString( "%1.SetDimension( %2 );" )
.arg( aPolylineName ).arg( aDim );
// Set polilyne data
- PolylineData aPolylineData = getPolylineData();
+ PolylineData aPolylineData = GetPolylineData();
if ( !aPolylineData.isEmpty() )
{
QString aPolylineDataName = "polyline_data";
aResList << QString( "%1.append( %2 );" )
.arg( aPolylineDataName ).arg( aPolylineSectName );
}
+ aResList << QString( "" );
- aResList << QString( "%1.setPolylineData( %2 );" )
+ aResList << QString( "%1.SetPolylineData( %2 );" )
.arg( aPolylineName ).arg( aPolylineDataName );
}
QVariant HYDROData_Polyline::GetDataVariant()
{
- QPainterPath aPath = painterPath();
+ QPainterPath aPath = GetPainterPath();
QVariant aVarData;
aVarData.setValue<QPainterPath>( aPath );
return aVarData;
}
-/**
- * Return polyline dimension
- * \return polyline dimension. 2 or 3 is valid. 0 is invalid.
- */
-int HYDROData_Polyline::getDimension() const
-{
- Handle(TDataStd_Integer) aDim;
- if(!myLab.FindAttribute(TDataStd_Integer::GetID(), aDim))
- return 0;
- return aDim->Get();
-}
-
-/**
- * Set polyline dimension. Should be 2 or 3.
- * \param theDimension the polyline dimension
- */
-void HYDROData_Polyline::setDimension( int theDimension )
-{
- removeAll();
- int aDim=0;
- if( theDimension == 2 || theDimension == 3){
- aDim = theDimension;
- }
- TDataStd_Integer::Set(myLab, aDim);
-}
-
/**
* Replace current polyline data by new sections list
* \param theSections the sections list
*/
-void HYDROData_Polyline::setPolylineData( const PolylineData& theSections )
+void HYDROData_Polyline::SetPolylineData( const PolylineData& theSections )
{
//Keep dimension
- int aDim = getDimension();
+ int aDim = GetDimension();
if( aDim == 0 )
return;
- removeAll();
- setDimension(aDim);
+ RemoveAll();
+ SetDimension(aDim);
if( theSections.size() == 0 )
return;
aPtr++;
}
}
+
+ UpdateWire( theSections );
}
/**
* Return polyline data
* \return polyline section list
*/
-HYDROData_Polyline::PolylineData HYDROData_Polyline::getPolylineData() const
+HYDROData_Polyline::PolylineData HYDROData_Polyline::GetPolylineData() const
{
int aSectCnt;
PolylineData aRes;
/**
* Returns true if polyline is closed
*/
-bool HYDROData_Polyline::isClosed() const
+bool HYDROData_Polyline::IsClosed() const
{
- int aDim = getDimension();
- PolylineData aPolylineData = getPolylineData();
+ int aDim = GetDimension();
+ PolylineData aPolylineData = GetPolylineData();
if ( aDim == 0 || aPolylineData.isEmpty() )
return false;
return true;
}
+/**
+ * Return polyline dimension
+ * \return polyline dimension. 2 or 3 is valid. 0 is invalid.
+ */
+int HYDROData_Polyline::GetDimension() const
+{
+ Handle(TDataStd_Integer) aDim;
+ if(!myLab.FindAttribute(TDataStd_Integer::GetID(), aDim))
+ return 0;
+ return aDim->Get();
+}
+
+/**
+ * Set polyline dimension. Should be 2 or 3.
+ * \param theDimension the polyline dimension
+ */
+void HYDROData_Polyline::SetDimension( int theDimension )
+{
+ RemoveAll();
+ int aDim=0;
+ if( theDimension == 2 || theDimension == 3){
+ aDim = theDimension;
+ }
+ TDataStd_Integer::Set(myLab, aDim);
+}
+
/**
* Remove all polyline attributes except dimension.
*/
-void HYDROData_Polyline::removeAll()
+void HYDROData_Polyline::RemoveAll()
{
//Remove only section data
TDF_Label aLab = myLab.FindChild( DataTag_SectionsSize );
}
/**
- * Return polyline painter path. Current implementation
- * is ignored section type.
+ * Returns the painter path.
+ * Note: currently only the first section of the polyline data is taken into account.
* \return polyline painter path.
*/
-QPainterPath HYDROData_Polyline::painterPath() const
+QPainterPath HYDROData_Polyline::GetPainterPath() const
{
QPainterPath aPath;
- int aDim = getDimension();
- if( ( aDim != 2 ) && ( aDim != 3) )
- return aPath;
- PolylineData aSects = getPolylineData();
- for( int i = 0 ; i < aSects.size() ; i++ ){
- int aPntCnt = aSects[i].myCoords.size()/aDim;
- if( aPntCnt ){
- aPath.moveTo(aSects[i].myCoords[0], aSects[i].myCoords[1] );
- }
- for( int j = 1 ; j < aPntCnt ; j++ ){
- int anIndx = j*aDim;
- aPath.lineTo(aSects[i].myCoords[anIndx], aSects[i].myCoords[anIndx+1]);
+ int aDim = GetDimension();
+ if( aDim != 2 && aDim != 3 )
+ return aPath;
+
+ PolylineData aSects = GetPolylineData();
+ if( aSects.isEmpty() )
+ return aPath;
+
+ PolylineSection aSection = aSects.first();
+ int aPntCount = aSection.myCoords.size() / aDim;
+ PolylineSection::SectionType aSectionType = aSection.myType;
+ bool anIsSectionClosed = aSection.myIsClosed;
+ if( aSectionType == PolylineSection::SECTION_POLYLINE )
+ {
+ if( aPntCount )
+ aPath.moveTo( aSection.myCoords[0], aSection.myCoords[1] );
+ for( int i = 1; i < aPntCount; i++ )
+ {
+ int anIndex = i * aDim;
+ aPath.lineTo( aSection.myCoords[ anIndex ], aSection.myCoords[ anIndex + 1 ] );
}
- if( aSects[i].myIsClosed ){
+ if( anIsSectionClosed )
aPath.closeSubpath();
+ }
+ else //if( aSectionType == PolylineSection::SECTION_SPLINE )
+ {
+ QList<double> aPoints;
+ for( int i = 0; i < aPntCount; i++ )
+ {
+ int anIndex = i * aDim;
+ aPoints << aSection.myCoords[ anIndex ] << aSection.myCoords[ anIndex + 1 ];
}
+ HYDROData_BSplineOperation aBSpline( aPoints, 0, anIsSectionClosed );
+ aPath = aBSpline.ComputePath();
}
return aPath;
}
+
+void HYDROData_Polyline::SetZValue( const double theZValue )
+{
+ TDataStd_Real::Set(myLab.FindChild(DataTag_ZValue), theZValue);
+}
+
+double HYDROData_Polyline::ZValue() const
+{
+ Handle(TDataStd_Real) aZValue;
+ if(myLab.FindChild(DataTag_ZValue).FindAttribute(TDataStd_Real::GetID(), aZValue))
+ return aZValue->Get();
+ return 0;
+}
+
+void HYDROData_Polyline::UpdateWire( const PolylineData& theSections )
+{
+ BRepBuilderAPI_MakeWire aMakeWire;
+
+ int aDim = GetDimension();
+
+ double aZValue = ZValue();
+
+ int aSectionCount = theSections.size();
+ for( int aSectionId = 0; aSectionId < aSectionCount; aSectionId++ )
+ {
+ const PolylineSection& aSection = theSections[ aSectionId ];
+ PolylineSection::SectionType aSectionType = aSection.myType;
+ bool anIsSectionClosed = aSection.myIsClosed;
+ int aPointCount = aSection.myCoords.size() / aDim;
+ if( aPointCount > 1 )
+ {
+ BRepBuilderAPI_MakeWire aMakeSectionWire;
+ if( aSectionType == PolylineSection::SECTION_POLYLINE )
+ {
+ for( int aPointId = 0; aPointId < aPointCount; aPointId++ )
+ {
+ int anId1 = aDim * aPointId;
+ int anId2 = aDim * ( aPointId + 1 );
+ if( aPointId == aPointCount - 1 )
+ {
+ if( anIsSectionClosed )
+ anId2 = 0;
+ else
+ break;
+ }
+
+ gp_Pnt aPnt1( aSection.myCoords[ anId1 ], aSection.myCoords[ anId1 + 1 ], aZValue );
+ gp_Pnt aPnt2( aSection.myCoords[ anId2 ], aSection.myCoords[ anId2 + 1 ], aZValue );
+
+ TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge( aPnt1, aPnt2 ).Edge();
+ aMakeSectionWire.Add( anEdge );
+ }
+ }
+ else //if( aSectionType == PolylineSection::SECTION_SPLINE )
+ {
+ QList<double> aPoints;
+ for( int aPointId = 0; aPointId < aPointCount; aPointId++ )
+ {
+ int anId = aPointId * aDim;
+ double x = aSection.myCoords[ anId ];
+ double y = aSection.myCoords[ anId+1 ];
+ aPoints << x << y;
+ }
+
+ HYDROData_BSplineOperation aBSpline( aPoints, aZValue, anIsSectionClosed );
+ TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge( aBSpline.Curve() ).Edge();
+ aMakeSectionWire.Add( anEdge );
+ }
+ TopoDS_Wire aSectionWire = aMakeSectionWire.Wire();
+ aMakeWire.Add( aSectionWire );
+ }
+ }
+
+ TopoDS_Wire aWire = aMakeWire.Wire();
+ SetTopShape( aWire );
+}