#include <TopTools_IndexedMapOfShape.hxx>
#include <BRepLib_MakeWire.hxx>
-//#define _DEVDEBUG_
+#define _DEVDEBUG_
#include "HYDRO_trace.hxx"
#include <BRepTools.hxx>
#include <sstream>
std::vector<TopoDS_Wire> aCurves;
GetWires(thePolyline, aCurves);
bool isOK = true;
+
+ std::vector<QColor> aSectColors;
+ int nbSec = thePolyline->NbSections();
+ for (int i = 0; i < nbSec; i++)
+ {
+ QColor aColor;
+ thePolyline->GetSectionColor(i, aColor);
+ aSectColors.push_back(aColor);
+ }
+
+ bool bsetColor = aCurves.size() == aSectColors.size();
for( int i=0, n=aCurves.size(); i<n; i++ )
{
std::vector<TopoDS_Shape> aCurvesList;
Split( aCurves[i], thePoint, theTolerance, aCurvesList );
- bool isLocalOK = CreatePolylines( theDoc, thePolyline, aCurvesList, true );
+ NCollection_IndexedDataMap<Handle(HYDROData_PolylineXY), TopoDS_Shape> outPoly2Sh;
+ bool isLocalOK = CreatePolylines( theDoc, thePolyline, aCurvesList, true, outPoly2Sh );
isOK = isOK && isLocalOK;
+ if (bsetColor)
+ {
+ QColor aColor = aSectColors[i];
+ if( aColor.isValid() )
+ {
+ for (int j=1;j<=outPoly2Sh.Extent();j++)
+ {
+ const Handle(HYDROData_PolylineXY)& Poly = outPoly2Sh.FindKey(j);
+ int nbSec = Poly->NbSections();
+ for (int k = 0; k < nbSec; k++)
+ Poly->SetSectionColor(k, aColor);
+ }
+ }
+ }
}
+
return isOK;
}
NCollection_Sequence<TCollection_AsciiString> aSectNames;
NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
NCollection_Sequence<bool> aSectClosures;
- aPolyline->GetSections( aSectNames, aSectTypes, aSectClosures );
+ aPolyline->GetSections( aSectNames, aSectTypes, aSectClosures );
for ( int i = 1, n = aSectNames.Size(); i <= n; ++i )
{
bool aSectClosure = aSectClosures.Value( i );
aNewPolyline->AddSection(aSectName, aSectType, aSectClosure);
HYDROData_PolylineXY::PointsList aPointsList = aPolyline->GetPoints(i-1, false);
- aNewPolyline->SetPoints(ins++, aPointsList);
+ QColor sectColor;
+ aPolyline->GetSectionColor(i-1, sectColor);
+ aNewPolyline->SetPoints(ins, aPointsList);
+ if (sectColor.isValid())
+ aNewPolyline->SetSectionColor(ins, sectColor);
+ ins++;
}
}
QString aName = theName;
return false;
}
+ std::vector<QColor> aSectColors;
+ int nbSec = thePolyline->NbSections();
+
const int aPSCount = aCurves.size();
const int aTSCount = aToolCurves.size();
std::vector<TopoDS_Shape> aResult;
+
+ bool bSetColor = aPSCount == nbSec;
+ if (bSetColor)
+ {
+ for (int i = 0; i < nbSec; i++)
+ {
+ QColor aColor;
+ thePolyline->GetSectionColor(i, aColor);
+ aSectColors.push_back(aColor);
+ }
+ }
+ NCollection_DataMap <TopoDS_Shape, QColor, TopTools_ShapeMapHasher> W2Color;
+
for (int aPSI = 0; aPSI < aPSCount; ++aPSI)
{
HYDROData_TopoCurve aCurve;
DEBTRACE("Initialize curve " << aPSI);
- if (!aCurve.Initialize(aCurves[aPSI]))
+ if (!aCurve.Initialize(aCurves[aPSI])) // empty, non manifold (or internal bug!)
{
+ DEBTRACE("discarded curve (empty or non manifold)!");
continue;
}
aSplitCurves.end();
for (int iw=0; aCIt != aLastCIt; ++aCIt, iw++)
{
- std::stringstream brepName;
- brepName << "theSplitWire_";
- brepName << iw;
- brepName << ".brep";
- BRepTools::Write(aCIt->Wire() , brepName.str().c_str() );
- aResult.push_back(aCIt->Wire());
+ //std::stringstream brepName;
+ //brepName << "theSplitWire_";
+ //brepName << iw;
+ //brepName << ".brep";
+ //BRepTools::Write(aCIt->Wire() , brepName.str().c_str() );
+ const TopoDS_Wire& aW = aCIt->Wire();
+ if (bSetColor)
+ W2Color.Bind(aW, aSectColors[aPSI]);
+ aResult.push_back(aW);
}
}
- CreatePolylines( theDoc, thePolyline, aResult, true );
+ NCollection_IndexedDataMap<Handle(HYDROData_PolylineXY), TopoDS_Shape> outPoly2Sh;
+ CreatePolylines( theDoc, thePolyline, aResult, true, outPoly2Sh );
+
+ for (int j=1;j<=outPoly2Sh.Extent();j++)
+ {
+ const Handle(HYDROData_PolylineXY)& Poly = outPoly2Sh.FindKey(j);
+ const TopoDS_Shape& Sh = outPoly2Sh.FindFromIndex(j);
+
+ int nbSec = Poly->NbSections();
+ for (int k = 0; k < nbSec; k++)
+ {
+ const QColor* color = W2Color.Seek(Sh);
+ if (color)
+ Poly->SetSectionColor(k, *color);
+ }
+ }
+
return true;
}
bool HYDROData_PolylineOperator::CreatePolylines( const Handle( HYDROData_Document )& theDoc,
const Handle( HYDROData_PolylineXY )& theOldPolyline,
const std::vector<TopoDS_Shape>& theShapes,
- bool isUseIndices )
+ bool isUseIndices,
+ NCollection_IndexedDataMap<Handle(HYDROData_PolylineXY), TopoDS_Shape>& outPoly2Sh)
{
if( theDoc.IsNull() )
return false;
if ( theOldPolyline.IsNull() )
return false;
const QString& theNamePrefix = theOldPolyline->GetName();
- const QColor& theColor = theOldPolyline->GetWireColor();
int n = theShapes.size();
DEBTRACE("theShapes.size() "<< n);
aPolyline->SetName( theNamePrefix );
}
- if( theColor.isValid() )
- aPolyline->SetWireColor( theColor );
+ outPoly2Sh.Add(aPolyline, theShapes[i]);
}
return true;
}