#include <QColor>
#include <Geom_BSplineCurve.hxx>
+#define _DEVDEBUG_
+#include "HYDRO_trace.hxx"
+#include <BRepTools.hxx>
+#include <sstream>
+
template<class T> void append( std::vector<T>& theList, const std::vector<T>& theList2 )
{
int aSize = theList.size();
for (int aPSI = 0; aPSI < aPSCount; ++aPSI)
{
HYDROData_TopoCurve aCurve;
+ DEBTRACE("Initialize curve " << aPSI);
if (!aCurve.Initialize(aCurves[aPSI]))
{
continue;
aSplitCurves.begin();
std::deque<HYDROData_TopoCurve>::const_iterator aLastCIt =
aSplitCurves.end();
- for (; aCIt != aLastCIt; ++aCIt)
+ for (int iw=0; aCIt != aLastCIt; ++aCIt, iw++)
{
- aResult.push_back(aCIt->Wire());
+ std::stringstream brepName;
+ brepName << "theSplitWire_";
+ brepName << iw;
+ brepName << ".brep";
+ BRepTools::Write(aCIt->Wire() , brepName.str().c_str() );
+ aResult.push_back(aCIt->Wire());
}
}
CreatePolylines( theDoc, thePolyline->GetName(), aResult, true, thePolyline->GetWireColor() );
+ //CreatePolylinesSplit( theDoc, thePolyline, aResult, true );
return true;
}
}
}
+//bool HYDROData_PolylineOperator::CreatePolylinesSplit(const Handle( HYDROData_Document )& theDoc,
+// const Handle( HYDROData_PolylineXY )& thePolyline,
+// const std::vector<TopoDS_Shape>& theShapes, bool isUseIndices)
+//{
+//
+// if (theDoc.IsNull())
+// return false;
+//
+// int nbSections = thePolyline->NbSections();
+// const QString& theNamePrefix = thePolyline->GetName();
+// const QColor& theColor = thePolyline->GetWireColor();
+//
+// int n = theShapes.size();
+// DEBTRACE("theShapes.size() "<< n);
+// int anIndex = 1;
+// for (int i = 0; i < n; i++)
+// {
+// Handle( HYDROData_PolylineXY ) aPolyline =
+// Handle( HYDROData_PolylineXY )::DownCast(theDoc->CreateObject(KIND_POLYLINEXY));
+// if (aPolyline.IsNull())
+// return false;
+//
+// for (int isec = 0; isec < nbSections; isec++)
+// {
+// gp_XY p = gp_XY(0, 0);
+// //double d = thePolyline->GetMinDistance(isec, p);
+// }
+//
+// if (isUseIndices)
+// {
+// QString aNewName = theNamePrefix + "_" + QString::number(anIndex);
+// while (!theDoc->FindObjectByName(aNewName).IsNull()) // the object with such a name is not found
+// {
+// anIndex++;
+// aNewName = theNamePrefix + "_" + QString::number(anIndex);
+// }
+// aPolyline->SetName(aNewName);
+// }
+// else
+// {
+// aPolyline->SetName(theNamePrefix);
+// }
+//
+// if (theColor.isValid())
+// aPolyline->SetWireColor(theColor);
+// }
+// return true;
+//
+//}
+
bool HYDROData_PolylineOperator::CreatePolylines( const Handle( HYDROData_Document )& theDoc,
const QString& theNamePrefix,
const std::vector<TopoDS_Shape>& theShapes,
return false;
int n = theShapes.size();
+ DEBTRACE("theShapes.size() "<< n);
int anIndex = 1;
for( int i=0; i<n; i++ )
{
if( aPolyline.IsNull() )
return false;
- aPolyline->SetShape( theShapes[i] );
+ aPolyline->ImportShape(theShapes[i], false);
+ //aPolyline->SetShape( theShapes[i] );
+
if( isUseIndices )
{
#include "HYDROData_Document.h"
#include "HYDROData_ShapesTool.h"
#include "HYDROData_Tool.h"
+#include "HYDROData_PolylineOperator.h"
+#include "HYDROData_TopoCurve.h"
#include <BRep_Builder.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <GCPnts_AbscissaPoint.hxx>
#include <GCPnts_QuasiUniformDeflection.hxx>
+#include <GCPnts_UniformDeflection.hxx>
#include <ImageComposer_MetaTypes.h>
#include <QPainterPath>
#include <QVariant>
+#define _DEVDEBUG_
+#include "HYDRO_trace.hxx"
+#include <BRepTools.hxx>
+#include <sstream>
+
static const Standard_GUID GUID_IS_UNEDITABLE("e5799736-9030-4051-91a4-2e58321fa153");
const double LOCAL_SELECTION_TOLERANCE = 0.0001;
BRepAdaptor_Curve anAdaptorCurve( theEdge );
GCPnts_QuasiUniformDeflection aDiscrete( anAdaptorCurve, theDeflection );
+ //GCPnts_UniformDeflection aDiscrete( anAdaptorCurve, theDeflection );
int aNbPoints = aDiscrete.NbPoints();
return true;
}
+
+bool convertEdgesToSections( const TopoDS_Edge& theEdge,
+ NCollection_Sequence<TCollection_AsciiString>& theSectNames,
+ NCollection_Sequence<HYDROData_PolylineXY::SectionType>& theSectTypes,
+ NCollection_Sequence<bool>& theSectClosures,
+ NCollection_Sequence<HYDROData_PolylineXY::PointsList>& theSectPoints,
+ bool IsCanBeClosed,
+ bool IsInterpolationAllowed,
+ double theDeflection )
+{
+ DEBTRACE("convertEdgesToSections")
+ Standard_Real aFirst = 0.0, aLast = 0.0;
+ Handle(Geom_Curve) anEdgeGeomCurve = BRep_Tool::Curve( theEdge, aFirst, aLast );
+ if ( anEdgeGeomCurve.IsNull() )
+ return false;
+
+ bool isPrevious = (theSectTypes.Size() > 0);
+ DEBTRACE("nb sections: " << theSectTypes.Size());
+ HYDROData_PolylineXY::SectionType prevSectType = HYDROData_PolylineXY::SECTION_SPLINE;;
+ HYDROData_PolylineXY::PointsList prevPointList;
+ bool isPrevClosed = true;
+ if (isPrevious)
+ {
+ prevSectType = theSectTypes.Last();
+ prevPointList = theSectPoints.Last();
+ isPrevClosed = theSectClosures.Last();
+ }
+
+ bool anIsEdgeClosed = anEdgeGeomCurve->IsClosed();
+ HYDROData_PolylineXY::SectionType aSectionType ;
+ if( anEdgeGeomCurve->IsKind( STANDARD_TYPE(Geom_Line) ) )
+ {
+ aSectionType = HYDROData_PolylineXY::SECTION_POLYLINE;
+ }
+ else if ( anEdgeGeomCurve->IsKind( STANDARD_TYPE(Geom_BSplineCurve) ) || IsInterpolationAllowed )
+ {
+ aSectionType = HYDROData_PolylineXY::SECTION_SPLINE;
+ }
+ else
+ {
+ // Other curve types are not supported
+ return false;
+ }
+
+ bool isNewSection = !isPrevious || isPrevClosed || anIsEdgeClosed || prevSectType != aSectionType;
+ DEBTRACE(isNewSection <<": " << !isPrevious << " " << isPrevClosed << " " << anIsEdgeClosed << " " << (prevSectType != aSectionType));
+
+ HYDROData_PolylineXY::PointsList aPointsList;
+ if (!isNewSection)
+ {
+ aPointsList = prevPointList;
+ }
+
+ if( aSectionType == HYDROData_PolylineXY::SECTION_POLYLINE )
+ {
+ DEBTRACE("SECTION_POLYLINE");
+ Handle(Geom_Line) aGeomLine = Handle(Geom_Line)::DownCast( anEdgeGeomCurve );
+
+ gp_Pnt aFirstPoint, aLastPoint;
+ aGeomLine->D0( aFirst, aFirstPoint );
+ aGeomLine->D0( aLast, aLastPoint );
+ HYDROData_PolylineXY::Point aSectFirstPoint( aFirstPoint.X(), aFirstPoint.Y() );
+ HYDROData_PolylineXY::Point aSectLastPoint( aLastPoint.X(), aLastPoint.Y() );
+ if (!isNewSection)
+ {
+ if (aSectFirstPoint == prevPointList.Last())
+ {
+ DEBTRACE("points shared: a");//aPointsList.Append( aSectFirstPoint );
+ aPointsList.Append( aSectLastPoint );
+ }
+ else if (aSectLastPoint == prevPointList.Last())
+ {
+ DEBTRACE("points shared: b");//aPointsList.Append( aSectLastPoint );
+ aPointsList.Append( aSectFirstPoint );
+ }
+ else if (aSectFirstPoint == prevPointList.First())
+ {
+ DEBTRACE("points shared: c");//aPointsList.Prepend( aSectFirstPoint );
+ aPointsList.Prepend( aSectLastPoint );
+ }
+ else if (aSectLastPoint == prevPointList.First())
+ {
+ DEBTRACE("points shared: d");//aPointsList.Prepend( aSectLastPoint );
+ aPointsList.Prepend( aSectFirstPoint );
+ }
+ else
+ {
+ DEBTRACE("no point shared")
+ isNewSection = true; // no point shared, new section
+ aPointsList.Clear();
+ aPointsList.Append( aSectFirstPoint );
+ aPointsList.Append( aSectLastPoint );
+ }
+ }
+ else
+ {
+ DEBTRACE("new section");
+ aPointsList.Append( aSectFirstPoint );
+ aPointsList.Append( aSectLastPoint );
+ }
+ }
+ else // aSectionType == HYDROData_PolylineXY::SECTION_SPLINE
+ {
+ DEBTRACE("SECTION_SPLINE");
+ isNewSection = true;
+ aPointsList.Clear();
+
+ BRepAdaptor_Curve anAdaptorCurve( theEdge );
+ GCPnts_QuasiUniformDeflection aDiscrete( anAdaptorCurve, theDeflection );
+
+ int aNbPoints = aDiscrete.NbPoints();
+
+ // Decrease the number of imported poles because of last one
+ // pole is the closing point which are the start point
+ if ( anIsEdgeClosed ) aNbPoints--;
+
+ for ( int i = 1; i <= aNbPoints; ++i )
+ {
+ const gp_Pnt& aPoint = aDiscrete.Value( i );
+
+ HYDROData_PolylineXY::Point aSectPoint( aPoint.X(), aPoint.Y() );
+ aPointsList.Append( aSectPoint );
+ }
+ }
+
+ if ( aPointsList.IsEmpty() )
+ return false;
+
+ TCollection_AsciiString aSectName = getUniqueSectionName( theSectNames );
+ if (isNewSection)
+ {
+ DEBTRACE("isNewSection");
+ theSectNames.Append( aSectName );
+ theSectTypes.Append( aSectionType );
+ theSectClosures.Append( anIsEdgeClosed );
+ theSectPoints.Append( aPointsList );
+ }
+ else
+ {
+ DEBTRACE("sameSection");
+ theSectPoints.SetValue(theSectPoints.Length(), aPointsList);
+ }
+
+ return true;
+}
+
bool HYDROData_PolylineXY::ImportShape( const TopoDS_Shape& theShape,
bool IsInterpolationAllowed,
double theDeviation )
{
+ DEBTRACE("ImportShape");
if ( theShape.IsNull() )
return false;
if ( theShape.ShapeType() == TopAbs_EDGE )
{
+ DEBTRACE("TopAbs_EDGE");
TopoDS_Edge anEdge = TopoDS::Edge( theShape );
anIsCanBeImported = convertEdgeToSection( anEdge, aSectNames, aSectTypes,
aSectClosures, aSectPoints, true, IsInterpolationAllowed, theDeviation );
}
else if ( theShape.ShapeType() == TopAbs_WIRE )
{
+ DEBTRACE("TopAbs_WIRE");
TopTools_SequenceOfShape anEdges;
HYDROData_ShapesTool::ExploreShapeToShapes( theShape, TopAbs_EDGE, anEdges );
for ( int i = 1, n = anEdges.Length(); i <= n && anIsCanBeImported; ++i )
{
TopoDS_Edge aWireEdge = TopoDS::Edge( anEdges.Value( i ) );
- anIsCanBeImported = convertEdgeToSection( aWireEdge, aSectNames, aSectTypes,
+ anIsCanBeImported = convertEdgesToSections( aWireEdge, aSectNames, aSectTypes,
aSectClosures, aSectPoints, false, IsInterpolationAllowed, theDeviation );
}
}
return aResDistance;
}
+//double HYDROData_PolylineXY::GetMinDistance( const int theSectionIndex,
+// const Point& thePoint ) const
+//{
+// double aResDistance = -1;
+// if ( theSectionIndex < 0 || theSectionIndex >= NbSections() )
+// return aResDistance;
+//
+// std::vector<TopoDS_Wire> aCurves;
+// HYDROData_PolylineOperator::GetWires(this, aCurves);
+// if (aCurves.size() != NbSections())
+// {
+// DEBTRACE("nbCurves != nbSections " << aCurves.size() << " " << NbSections());
+// return aResDistance;
+// }
+// TopoDS_Wire aWire = aCurves[theSectionIndex];
+// TopTools_SequenceOfShape anEdges;
+// HYDROData_ShapesTool::ExploreShapeToShapes( aWire, TopAbs_EDGE, anEdges );
+// for ( int i = 1, n = anEdges.Length(); i <= n; ++i )
+// {
+// DEBTRACE("i: "<< i);
+// TopoDS_Edge aWireEdge = TopoDS::Edge( anEdges.Value( i ) );
+// gp_XYZ aPointz = gp_XYZ(thePoint.X(), thePoint.Y(), 0);
+// Adaptor3d_Curve theCurve = BRepAdaptor_Curve(aWireEdge);
+// double theParameter = -1;
+// double d = ProjectPointToCurve(aPointz, theCurve, theParameter);
+// if (d<aResDistance) aResDistance = d;
+// DEBTRACE("d[" << i <<"]=" << d);
+// }
+// DEBTRACE("distance section "<<theSectionIndex<<" point="<<aResDistance<<" ("<<thePoint.X()<<", "<< thePoint.Y()<<")");
+// return aResDistance;
+//}
+
int HYDROData_PolylineXY::NbSections() const
{
Handle(TDataStd_ExtStringList) aNamesList;
#include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
#include <TopTools_ListOfShape.hxx>
+#define _DEVDEBUG_
+#include "HYDRO_trace.hxx"
+#include <BRepTools.hxx>
+
//! The type is intended to traverse the container
//! either from the begin to the end or vice versa.
template<typename ContainerType, typename IteratorType>
TopExp::MapShapesAndAncestors(theWire,
TopAbs_VERTEX, TopAbs_EDGE, aVertexToEdges);
const int aVCount = aVertexToEdges.Extent();
+ DEBTRACE("initialize VCount= "<< aVCount);
if (aVCount == 0)
{
return false;
TopoDS_Wire HYDROData_TopoCurve::Wire() const
{
TopoDS_Wire aWire;
- BRep_Builder aBulder;
- aBulder.MakeWire(aWire);
+ BRep_Builder aBuilder;
+ aBuilder.MakeWire(aWire);
std::list<TopoDS_Edge>::const_iterator aEItLast = myEdges.end();
std::list<TopoDS_Edge>::const_iterator aEIt = myEdges.begin();
for (; aEIt != aEItLast; ++aEIt)
{
- aBulder.Add(aWire, *aEIt);
+ aBuilder.Add(aWire, *aEIt);
}
return aWire;
}
aParamI ^= 1;
}
const bool isClosed = IsClosed();
+ DEBTRACE("aParamI: " << aParamI << " isClosed: "<< isClosed);
if (aParamI < 0)
{
aEdge.Orientation(TopAbs_FORWARD);
const TopoDS_Wire& theWire,
std::deque<std::list<double> >& theParameters) const
{
+ std::string brepName = "theWireToIntersect";
+ brepName += ".brep";
+ BRepTools::Write( theWire, brepName.c_str() );
+
int aIntCount = 0;
theParameters.resize(myEdges.size());
std::list<TopoDS_Edge>::const_iterator aEIt = myEdges.begin();
aIntCount += IntersectEdge(aEdge,TopoDS::Edge(aEIt2.Current()), aParams);
}
}
+ DEBTRACE("aIntCount " << aIntCount);
return aIntCount;
}