#include <HYDROData_Object.h>
+#include <TopoDS_Face.hxx>
+
#include <QPointF>
#include <QList>
*/
//HYDRODATA_EXPORT virtual QVariant GetDataVariant();
+ /**
+ * Returns the shape of the the object.
+ */
+ HYDRODATA_EXPORT virtual TopoDS_Face Face() const = 0;
+
protected:
friend class HYDROData_Iterator;
#include <HYDROData_Polyline.h>
#include <HYDROData_Iterator.h>
+#include <HYDROOperations_BSpline.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_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>
aPtr++;
}
}
+
+ UpdateWire( theSections );
}
/**
}
/**
- * 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 aPath;
int aDim = getDimension();
- if( ( aDim != 2 ) && ( aDim != 3) )
- return aPath;
+ 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]);
+ 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 ];
}
+ HYDROOperations_BSpline aBSpline( aPoints, anIsSectionClosed );
+ aPath = aBSpline.ComputePath();
}
return aPath;
}
+
+void HYDROData_Polyline::SetWire( const TopoDS_Wire& theWire )
+{
+ TNaming_Builder aBuilder( myLab );
+ aBuilder.Generated( theWire );
+}
+
+TopoDS_Wire HYDROData_Polyline::Wire() const
+{
+ Handle(TNaming_NamedShape) aNamedShape;
+ if( myLab.FindAttribute( TNaming_NamedShape::GetID(), aNamedShape ) )
+ return TopoDS::Wire( aNamedShape->Get() );
+ return TopoDS_Wire();
+}
+
+void HYDROData_Polyline::UpdateWire( const PolylineData& theSections )
+{
+ BRepBuilderAPI_MakeWire aMakeWire;
+
+ int aDim = getDimension();
+
+ 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 ], 0 );
+ gp_Pnt aPnt2( aSection.myCoords[ anId2 ], aSection.myCoords[ anId2 + 1 ], 0 );
+
+ 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;
+ }
+
+ HYDROOperations_BSpline aBSpline( aPoints, 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();
+ SetWire( aWire );
+}
#include <QPainterPath>
#include <QList>
+class TopoDS_Wire;
+
DEFINE_STANDARD_HANDLE(HYDROData_Polyline, HYDROData_Object)
struct PolylineSection
DataTag_SectionsName,
DataTag_SectionsClosed,
DataTag_SectionsSize,
- DataTag_SectionsType
+ DataTag_SectionsType,
+ DataTag_Wire
};
public:
*/
HYDRODATA_EXPORT void removeAll();
-
/**
- * Returns the painter path. The painter path is construct by lines
+ * Returns the painter path.
+ * Note: currently only the first section of the polyline data is taken into account.
*/
HYDRODATA_EXPORT QPainterPath painterPath() const;
+ /**
+ * Sets the wire contour of the object.
+ */
+ HYDRODATA_EXPORT void SetWire( const TopoDS_Wire& theWire );
+
+ /**
+ * Returns the wire contour of the object.
+ */
+ HYDRODATA_EXPORT TopoDS_Wire Wire() const;
+
+protected:
+ /**
+ * Update the wire contour on the basis of the polyline data.
+ */
+ void UpdateWire( const PolylineData& theSections );
protected:
#include "HYDROData_Region.h"
+#include <TNaming_Builder.hxx>
+#include <TNaming_NamedShape.hxx>
+#include <TopoDS.hxx>
+
#include <QString>
#define PYTHON_REGION_ID "KIND_REGION"
{
}
+void HYDROData_Region::SetFace( const TopoDS_Face& theFace )
+{
+ TNaming_Builder aBuilder( myLab );
+ aBuilder.Generated( theFace );
+}
+
+TopoDS_Face HYDROData_Region::Face() const
+{
+ Handle(TNaming_NamedShape) aNamedShape;
+ if( myLab.FindAttribute( TNaming_NamedShape::GetID(), aNamedShape ) )
+ return TopoDS::Face( aNamedShape->Get() );
+ return TopoDS_Face();
+}
+
QString HYDROData_Region::getPythonKindId() const
{
return QString( PYTHON_REGION_ID );
enum DataTag
{
DataTag_First = HYDROData_Domain::DataTag_First + 100, ///< first tag, to reserve
+ DataTag_Face
};
public:
*/
HYDRODATA_EXPORT virtual const ObjectKind GetKind() const { return KIND_REGION; }
+ /**
+ * Sets the shape of the object.
+ */
+ HYDRODATA_EXPORT void SetFace( const TopoDS_Face& theFace );
+
+ /**
+ * Returns the shape of the the object (redefined method).
+ */
+ HYDRODATA_EXPORT virtual TopoDS_Face Face() const;
+
protected:
friend class HYDROData_Iterator;
#include "HYDROData_Polyline.h"
#include "HYDROData_Iterator.h"
+#include <BRepBuilderAPI_MakeFace.hxx>
#include <TDataStd_IntegerArray.hxx>
+#include <TopoDS_Wire.hxx>
#include <QColor>
#include <QStringList>
ClearReferenceObjects( DataTag_Polyline );
}
-QPainterPath HYDROData_Zone::GetPainterPath() const
+TopoDS_Face HYDROData_Zone::Face() const
{
- QPainterPath aPath;
-
Handle(HYDROData_Polyline) aPolyline = GetPolyline();
- if ( !aPolyline.IsNull() )
+ if( !aPolyline.IsNull() )
{
- aPath = aPolyline->painterPath();
+ TopoDS_Wire aWire = aPolyline->Wire();
+ if( !aWire.IsNull() )
+ {
+ BRepBuilderAPI_MakeFace aMakeFace( aWire, Standard_True );
+ aMakeFace.Build();
+ if( aMakeFace.IsDone() )
+ return aMakeFace.Face();
+ }
}
-
- return aPath;
+ return TopoDS_Face();
}
QString HYDROData_Zone::getPythonKindId() const
#include <HYDROData_Domain.h>
-#include <QPainterPath>
class Handle(HYDROData_Polyline);
DEFINE_STANDARD_HANDLE(HYDROData_Zone, HYDROData_Domain)
//HYDRODATA_EXPORT virtual QVariant GetDataVariant();
/**
- * Returns the painter path. The painter path is construct by polyline
+ * Returns the shape of the the object (redefined method).
*/
- HYDRODATA_EXPORT QPainterPath GetPainterPath() const;
-
+ HYDRODATA_EXPORT TopoDS_Face Face() const;
protected:
#include<Geom_BezierCurve.hxx>
HYDROOperations_BSpline::HYDROOperations_BSpline(
- QList<double>& thePoints)
+ const QList<double>& thePoints,
+ const bool theIsClosed)
{
// fill array for algorithm by the received coordinates
int aLen = thePoints.size() / 2;
Handle(TColgp_HArray1OfPnt) aHCurvePoints = new TColgp_HArray1OfPnt (1, aLen);
- QList<double>::iterator aListIter = thePoints.begin();
+ QList<double>::const_iterator aListIter = thePoints.begin();
for (int ind = 1; ind <= aLen; ind++) {
gp_Pnt aPnt(gp::Origin());
aPnt.SetX(*aListIter);
aHCurvePoints->SetValue(ind, aPnt);
}
// compute BSpline
- GeomAPI_Interpolate aGBC(aHCurvePoints, Standard_False, gp::Resolution());
+ GeomAPI_Interpolate aGBC(aHCurvePoints, theIsClosed, gp::Resolution());
aGBC.Perform();
if (aGBC.IsDone()) {
myCurve = aGBC.Curve();
//! Creates a spline by list of coordinates: pairs X and Y
//! \param thePoints coordinates in format X1, Y1, X2, Y2, etc. must be even number of elements
- HYDROOperations_BSpline(QList<double>& thePoints);
+ //! \param theIsClosed flag indicating that the result spline should be closed
+ HYDROOperations_BSpline(const QList<double>& thePoints,
+ const bool theIsClosed);
//! Returns the BSpline curve passing through the points
//! \returns Null if Computation of BSpline was failed
#include "HYDROGUI_AISCurve.h"
-#include "CurveCreator_Curve.hxx"
+#include <HYDROOperations_BSpline.h>
+
+#include <CurveCreator_Curve.hxx>
#include <AIS_Point.hxx>
#include <AIS_Line.hxx>
-
+#include <AIS_Shape.hxx>
+#include <BRepBuilderAPI_MakeEdge.hxx>
+#include <BRepBuilderAPI_MakeWire.hxx>
+#include <Geom_CartesianPoint.hxx>
#include <gp_Pnt.hxx>
#include <gp_Lin.hxx>
-
-#include <Geom_CartesianPoint.hxx>
+#include <TopoDS_Edge.hxx>
+#include <TopoDS_Face.hxx>
+#include <TopoDS_Wire.hxx>
HYDROGUI_AISCurveSection::HYDROGUI_AISCurveSection( Handle_AIS_InteractiveContext theContext,
CurveCreator_Curve* theCurve, int theSection) :
Quantity_Color aColor = getActiveColor();
for( int i = 0 ; i < myObjects.size() ; i++ ){
myObjects[i]->SetColor(aColor);
- myContext->Display(myObjects[i]);
+ myContext->Display(myObjects[i], Standard_False);
}
+ myContext->UpdateCurrentViewer();
}
void HYDROGUI_AISCurveSection::Display()
{
for( int i = 0 ; i < myObjects.size() ; i++ ){
- myContext->Display(myObjects[i]);
+ myContext->Display(myObjects[i], Standard_False);
}
+ myContext->UpdateCurrentViewer();
}
void HYDROGUI_AISCurveSection::Erase()
{
for( int i = 0 ; i < myObjects.size() ; i++ ){
- myContext->Erase(myObjects[i]);
+ myContext->Erase(myObjects[i], Standard_False);
}
+ myContext->UpdateCurrentViewer();
}
void HYDROGUI_AISCurveSection::buildSection()
{
+ CurveCreator::Type aSectType = myCurve->getType( mySection );
int aSectSize = myCurve->getNbPoints( mySection );
- double anX;
- double anY;
- double aZ;
- int i = 0;
- for( ; i < ( aSectSize - 1 ) ; i++ ){
- Handle_AIS_Point anAISPnt = getAISPoint(i);
- myObjects.push_back( anAISPnt );
- Handle_AIS_Line aLine = getAISLine( i, i+1 );
- myObjects.push_back( aLine );
- }
- if( aSectSize != 0 ){
- Handle_AIS_Point anAISPnt = getAISPoint(i);
- myObjects.push_back( anAISPnt );
- if( myCurve->isClosed(mySection) && ( aSectSize > 1 ) ){
- Handle_AIS_Line aLine = getAISLine( i, 0 );
+ bool aSectIsClosed = myCurve->isClosed( mySection );
+
+ if( aSectType == CurveCreator::Polyline )
+ {
+ int i = 0;
+ for( ; i < ( aSectSize - 1 ) ; i++ ){
+ Handle_AIS_Point anAISPnt = getAISPoint(i);
+ myObjects.push_back( anAISPnt );
+ Handle_AIS_Line aLine = getAISLine( i, i+1 );
myObjects.push_back( aLine );
}
+ if( aSectSize != 0 ){
+ Handle_AIS_Point anAISPnt = getAISPoint(i);
+ myObjects.push_back( anAISPnt );
+ if( myCurve->isClosed(mySection) && ( aSectSize > 1 ) ){
+ Handle_AIS_Line aLine = getAISLine( i, 0 );
+ myObjects.push_back( aLine );
+ }
+ }
+ }
+ else if( aSectType == CurveCreator::BSpline )
+ {
+ QList<double> aPoints;
+ for( int i = 0; i < aSectSize; i++ )
+ {
+ Handle_AIS_Point anAISPnt = getAISPoint( i );
+ myObjects.push_back( anAISPnt );
+
+ double aX = 0, aY = 0, aZ = 0;
+ getPoint( i, aX, aY, aZ );
+ aPoints << aX << aY;
+ }
+
+ if( aSectSize > 1 )
+ {
+ HYDROOperations_BSpline aBSpline( aPoints, aSectIsClosed );
+ TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge( aBSpline.Curve() ).Edge();
+
+ TopoDS_Wire aWire = BRepBuilderAPI_MakeWire( anEdge ).Wire();
+
+ Handle(AIS_Shape) aShape = new AIS_Shape( aWire );
+ myObjects.push_back( aShape );
+ }
}
}
continue;
Region aRegion;
- // aRegion.SplitData.Path = aSplitZone->GetPainterPath();
- // aRegion.SplitData.ZoneNames ???
+ aRegion.SplitData.Shape = aDataRegion->Face();
aRegion.FillingColor = aDataRegion->GetFillingColor();
aRegion.BorderColor = aDataRegion->GetBorderColor();
continue;
// Fill the zone data
+ aDataRegion->SetFace( aRegion.SplitData.Face() );
+
aDataRegion->SetName( aRegion.RegionName );
aDataRegion->SetBorderColor( aRegion.BorderColor );
aDataRegion->SetFillingColor( aRegion.FillingColor );
aRegion.Shape->setFillingColor( aRegion.FillingColor, false );
aRegion.Shape->setBorderColor( aRegion.BorderColor, false );
- aRegion.Shape->setPath( aRegion.SplitData.Path, true );
+ aRegion.Shape->setFace( aRegion.SplitData.Face(), true );
}
//Process the draw events for viewer
void onViewPortMouseEvent( QGraphicsSceneMouseEvent* );
- void onTestSplit(); // ouv: tmp, to delete
-
private:
void updateGV( const bool theIsInit = false,
const bool theIsForced = false );
createMenu( FuseImagesId, aHydroId, -1, -1 );
createMenu( CutImagesId, aHydroId, -1, -1 );
createMenu( SplitImageId, aHydroId, -1, -1 );
-
- //ouv: debug
- //createMenu( separator(), aHydroId );
- //createMenu( TestSplitId, aHydroId, -1, -1 );
}
void HYDROGUI_Module::createPopups()
connect( anEditUndo, SIGNAL( triggered( int ) ), this, SLOT( onUndo( int ) ) );
connect( anEditRedo, SIGNAL( triggered( int ) ), this, SLOT( onRedo( int ) ) );
-
- QAction* aTestSplit = new QAction( "Test split", application()->desktop() );
- registerAction( TestSplitId, aTestSplit );
- connect( aTestSplit, SIGNAL( triggered() ), this, SLOT( onTestSplit() ) );
}
void HYDROGUI_Module::updateUndoRedoControls()
return anOp;
}
-
-//-----------------------------------------------------------------------------
-// Test splitting
-//-----------------------------------------------------------------------------
-#include <HYDROData_Iterator.h>
-#include <HYDROGUI_Tool.h>
-void HYDROGUI_Module::onTestSplit()
-{
- Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( getStudyId() );
-
- aDocument->StartOperation();
-
- HYDROData_SequenceOfObjects aZoneList;
- HYDROData_Iterator anIterator( aDocument, KIND_ZONE );
- for( ; anIterator.More(); anIterator.Next() )
- aZoneList.Append( anIterator.Current() );
-
- HYDROGUI_SplitZonesTool::SplitDataList aSplitDataList =
- HYDROGUI_SplitZonesTool::SplitZones( aZoneList, NULL );
-
- int anIndex = 0;
- HYDROGUI_SplitZonesTool::SplitDataListIterator anIter( aSplitDataList );
- while( anIter.hasNext() )
- {
- const HYDROGUI_SplitZonesTool::SplitData& aSplitData = anIter.next();
- const QPainterPath& aPath = aSplitData.Path;
- const QStringList& aZoneNames = aSplitData.ZoneNames;
-
- Handle(HYDROData_Polyline) aPolyline =
- Handle(HYDROData_Polyline)::DownCast( aDocument->CreateObject( KIND_POLYLINE ) );
- if( !aPolyline.IsNull() )
- {
- aPolyline->SetName( QString( "SplitPolyline_%1" ).arg( ++anIndex ) );
- aPolyline->setDimension( 2 );
-
- QList<PolylineSection> aPolylineData;
- for( int i = 0, n = aPath.elementCount(); i < n; i++ )
- {
- const QPainterPath::Element anElement = aPath.elementAt( i );
- switch( anElement.type )
- {
- case QPainterPath::MoveToElement:
- aPolylineData.append( PolylineSection() );
- break;
- case QPainterPath::LineToElement:
- if( !aPolylineData.isEmpty() )
- {
- PolylineSection& aSection = aPolylineData.last();
- aSection.myCoords << anElement.x;
- aSection.myCoords << anElement.y;
- }
- break;
- case QPainterPath::CurveToElement: // currently not supported
- default:
- break;
- }
- }
- aPolyline->setPolylineData( aPolylineData );
- }
-
- Handle(HYDROData_Zone) aZone =
- Handle(HYDROData_Zone)::DownCast( aDocument->CreateObject( KIND_ZONE ) );
- if( !aZone.IsNull() )
- {
- aZone->SetName( QString( "SplitZone_%1" ).arg( anIndex ) );
- aZone->SetPolyline( aPolyline );
-
- aZone->SetBorderColor( Qt::black );
-
- int aCounter = 0;
- int aR = 0, aG = 0, aB = 0;
- QStringListIterator aZoneNameIter( aZoneNames );
- while( aZoneNameIter.hasNext() )
- {
- const QString& aZoneName = aZoneNameIter.next();
- Handle(HYDROData_Zone) aRefZone = Handle(HYDROData_Zone)::DownCast(
- HYDROGUI_Tool::FindObjectByName( this, aZoneName, KIND_ZONE ) );
- if( !aRefZone.IsNull() )
- {
- QColor aRefColor = aRefZone->GetFillingColor();
- aR += aRefColor.red();
- aG += aRefColor.green();
- aB += aRefColor.blue();
- aCounter++;
- }
- }
- if( aCounter > 0 )
- {
- QColor aFillingColor( aR / aCounter, aG / aCounter, aB / aCounter );
- aZone->SetFillingColor( aFillingColor );
- }
- }
- }
-
- aDocument->CommitOperation();
- update( UF_Model );
-}
ShowAllId,
HideId,
HideAllId,
-
- TestSplitId
};
#endif
aPrsZone->setFillingColor( aZone->GetFillingColor() );
aPrsZone->setBorderColor( aZone->GetBorderColor() );
- aPrsZone->setPath( aZone->GetPainterPath() );
+ // ouv: the method is no more
+ //aPrsZone->setPath( aZone->GetPainterPath() );
aPrsZone->compute();
HYDROGUI_Shape::HYDROGUI_Shape( const Handle(AIS_InteractiveContext)& theContext )
: myContext( theContext ),
myIsHighlight( false ),
- myZIndex( 0.0 ),
myFillingColor( Qt::green ),
myBorderColor( Qt::black ),
myHighlightColor( Qt::white )
myShape.Nullify();
}
-void HYDROGUI_Shape::display()
+void HYDROGUI_Shape::display( const bool theIsUpdateViewer )
{
if ( !myContext || myShape.IsNull() )
return;
- myContext->Display( myShape );
+ myContext->Display( myShape, theIsUpdateViewer );
}
-void HYDROGUI_Shape::erase()
+void HYDROGUI_Shape::erase( const bool theIsUpdateViewer )
{
if ( !myContext || myShape.IsNull() )
return;
- myContext->Erase( myShape );
+ myContext->Erase( myShape, theIsUpdateViewer );
}
void HYDROGUI_Shape::highlight( bool theIsHighlight )
return myIsHighlight;
}
-void HYDROGUI_Shape::setPath( const QPainterPath& thePath,
- const bool theToDisplay )
-{
- myPath = thePath;
- buildShape();
- updateShape( theToDisplay );
-}
-
-QPainterPath HYDROGUI_Shape::getPath() const
+void HYDROGUI_Shape::setWire( const TopoDS_Wire& theWire,
+ const bool theToDisplay )
{
- return myPath;
+ BRepBuilderAPI_MakeFace aFaceBuilder( theWire, Standard_True );
+ aFaceBuilder.Build();
+ if( aFaceBuilder.IsDone() )
+ {
+ TopoDS_Face aFace = aFaceBuilder.Face();
+ setFace( aFace, theToDisplay );
+ }
}
-void HYDROGUI_Shape::setZIndex( const double theZIndex,
- const bool theToDisplay )
+void HYDROGUI_Shape::setFace( const TopoDS_Face& theFace,
+ const bool theToDisplay )
{
- myZIndex = theZIndex;
+ myFace = theFace;
buildShape();
updateShape( theToDisplay );
}
-double HYDROGUI_Shape::getZIndex() const
-{
- return myZIndex;
-}
-
void HYDROGUI_Shape::setFillingColor( const QColor& theColor,
const bool theToDisplay )
{
return myHighlightColor;
}
-void HYDROGUI_Shape::makeEdge( BRepBuilderAPI_MakeWire& theWireBuilder,
- gp_Pnt& theFirstPoint,
- gp_Pnt& theLastPoint ) const
-{
- BRepBuilderAPI_MakeEdge anEdgeBuilder( theFirstPoint, theLastPoint );
- anEdgeBuilder.Build();
- if ( anEdgeBuilder.IsDone() )
- {
- TopoDS_Edge anEdge = anEdgeBuilder;
- theWireBuilder.Add( anEdge );
- }
-}
-
-void HYDROGUI_Shape::makeWire( BRepBuilderAPI_MakeFace& theFaceBuilder,
- BRepBuilderAPI_MakeWire& theWireBuilder,
- bool& theIsComposed ) const
-{
- theWireBuilder.Build();
- if ( theWireBuilder.IsDone() )
- {
- TopoDS_Wire aBuildedWire = theWireBuilder;
- if ( theIsComposed )
- {
- theFaceBuilder.Add( aBuildedWire );
- }
- else
- {
- theFaceBuilder = BRepBuilderAPI_MakeFace( aBuildedWire, true );
-
- theFaceBuilder.Build();
- theIsComposed = theFaceBuilder.IsDone();
- }
- }
-
- theWireBuilder = BRepBuilderAPI_MakeWire();
-}
-
void HYDROGUI_Shape::buildShape()
{
// Erase previously created shape
erase();
- if ( myPath.isEmpty() )
+ if( myFace.IsNull() )
return;
- BRepBuilderAPI_MakeFace aFaceBuilder;
- BRepBuilderAPI_MakeWire aWireBuilder;
-
- // Build new shape from path
- bool anIsComposed = false;
- bool anIsStarted = false;
- gp_Pnt aStartPoint( 0, 0, myZIndex );
- gp_Pnt aPrevPoint( 0, 0, myZIndex );
-
- for ( int i = 0; i < myPath.elementCount(); ++i )
- {
- const QPainterPath::Element& aPathElem = myPath.elementAt( i );
-
- gp_Pnt aCurPoint( aPathElem.x, aPathElem.y, myZIndex );
- switch ( aPathElem.type )
- {
- case QPainterPath::LineToElement:
- {
- // Just build the edge
- makeEdge( aWireBuilder, aPrevPoint, aCurPoint );
- break;
- }
- case QPainterPath::CurveToElement:
- {
- // TODO
- break;
- }
- case QPainterPath::MoveToElement:
- {
- if ( anIsStarted )
- {
- // Compose face
- if ( !aStartPoint.IsEqual( aPrevPoint, Precision::Confusion() ) )
- {
- //Close wire
- makeEdge( aWireBuilder, aPrevPoint, aStartPoint );
- }
-
- // Make face wiyth edge
- makeWire( aFaceBuilder, aWireBuilder, anIsComposed );
- }
-
- anIsStarted = true;
- aStartPoint = aCurPoint;
- break;
- }
- default:
- break;
- }
-
- aPrevPoint = aCurPoint;
- }
-
- makeWire( aFaceBuilder, aWireBuilder, anIsComposed );
-
- TopoDS_Face aResShape;
-
- aFaceBuilder.Build();
- if ( aFaceBuilder.IsDone() )
- aResShape = aFaceBuilder;
-
- myShape = new AIS_Shape( aResShape );
+ myShape = new AIS_Shape( myFace );
myShape->SetTransparency( 0 );
myShape->SetDisplayMode( AIS_Shaded );
if ( !aShadingAspect.IsNull() )
{
Graphic3d_MaterialAspect aMatAspect;
- aMatAspect.SetAmbient( 1 );
- aMatAspect.SetDiffuse( 0 );
-
- aShadingAspect->Aspect()->SetFrontMaterial( aMatAspect );
- aShadingAspect->Aspect()->SetBackMaterial( aMatAspect );
+ aMatAspect.SetAmbient( 1 );
+ aMatAspect.SetDiffuse( 0 );
+
+ aShadingAspect->Aspect()->SetFrontMaterial( aMatAspect );
+ aShadingAspect->Aspect()->SetBackMaterial( aMatAspect );
}
}
}
if ( !theIsForce || !myContext )
return;
- myContext->Display( myShape );
+ myContext->Display( myShape, theIsForce );
}
QColor HYDROGUI_Shape::getActiveColor() const
#include <AIS_InteractiveContext.hxx>
#include <AIS_Shape.hxx>
+#include <TopoDS_Face.hxx>
+#include <TopoDS_Wire.hxx>
+
#include <QColor>
-#include <QPainterPath>
class BRepBuilderAPI_MakeFace;
class BRepBuilderAPI_MakeWire;
~HYDROGUI_Shape();
public:
- virtual void display();
- virtual void erase();
+ virtual void display( const bool theIsUpdateViewer = true );
+ virtual void erase( const bool theIsUpdateViewer = true );
virtual void highlight( bool theIsHighlight );
virtual bool isHighlighted() const;
- virtual void setPath( const QPainterPath& thePath,
- const bool theToDisplay = true );
- virtual QPainterPath getPath() const;
+ virtual void setWire( const TopoDS_Wire& theWire,
+ const bool theToDisplay = true );
- virtual void setZIndex( const double theZIndex,
- const bool theToDisplay = true );
- virtual double getZIndex() const;
+ virtual void setFace( const TopoDS_Face& theFace,
+ const bool theToDisplay = true );
virtual void setFillingColor( const QColor& theColor,
const bool theToDisplay = true );
static double getQuantityColorVal( const int theColorVal );
void colorShapeBorder( const QColor& theColor );
- void makeEdge( BRepBuilderAPI_MakeWire& theWireBuilder,
- gp_Pnt& theFirstPoint,
- gp_Pnt& theLastPoint ) const;
-
- void makeWire( BRepBuilderAPI_MakeFace& theFaceBuilder,
- BRepBuilderAPI_MakeWire& theWireBuilder,
- bool& theIsComposed ) const;
-
private:
Handle(AIS_InteractiveContext) myContext;
Handle(AIS_Shape) myShape;
bool myIsHighlight;
- QPainterPath myPath;
+ TopoDS_Face myFace;
- double myZIndex;
QColor myFillingColor;
QColor myBorderColor;
QColor myHighlightColor;
#include <HYDROData_Polyline.h>
#include <HYDROData_Zone.h>
-void printPath( const QString& thePathName,
- const QPainterPath& thePath,
- const QStringList& theZonesList = QStringList() )
+#include <BRepAlgoAPI_Common.hxx>
+#include <BRepAlgoAPI_Cut.hxx>
+#include <BRepBuilderAPI_MakeFace.hxx>
+#include <TopExp_Explorer.hxx>
+#include <TopoDS.hxx>
+#include <TopoDS_Iterator.hxx>
+#include <TopoDS_Wire.hxx>
+
+TopoDS_Face HYDROGUI_SplitZonesTool::SplitData::Face() const
{
- printf( "%s ", qPrintable( thePathName ) );
- if( !theZonesList.isEmpty() )
- {
- printf( "[ " );
- QStringListIterator anIter( theZonesList );
- while( anIter.hasNext() )
- printf( "%s ", qPrintable( anIter.next() ) );
- printf( "] " );
- }
- printf( "(n=%d) :", thePath.elementCount() );
- for( int i = 0, n = thePath.elementCount(); i < n; i++ )
- {
- const QPainterPath::Element anElement = thePath.elementAt( i );
- switch( anElement.type )
- {
- case QPainterPath::MoveToElement:
- printf( " M(%.0f,%.0f)", anElement.x, anElement.y );
- break;
- case QPainterPath::LineToElement:
- printf( " L(%.0f,%.0f)", anElement.x, anElement.y );
- break;
- default:
- break;
- }
- }
- printf( "\n" );
+ if( !Shape.IsNull() && Shape.ShapeType() == TopAbs_FACE )
+ return TopoDS::Face( Shape );
+ return TopoDS_Face();
}
HYDROGUI_SplitZonesTool::SplitDataList
Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( theZoneList.Value( anIndex ) );
if( !aZone.IsNull() )
{
- SplitData aSplitData( aZone->GetPainterPath(), aZone->GetName() );
+ SplitData aSplitData( aZone->Face(), aZone->GetName() );
anInputSplitDataList.append( aSplitData );
}
}
// Step 1. Split the paths.
- //printf( "Step 1\n" );
SplitDataListIterator anInputIter( anInputSplitDataList );
while( anInputIter.hasNext() )
{
}
// Step 2. Take into account the boundary polyline.
- //printf( "Step 2\n" );
if( !thePolyline.IsNull() )
{
- const QPainterPath& aBoundaryPath = thePolyline->painterPath();
- SplitData aBoundarySplitData( aBoundaryPath, "" );
-
- SplitDataList aCutSplitDataList;
- SplitDataListIterator anOutputIter( anOutputSplitDataList );
- while( anOutputIter.hasNext() )
+ const TopoDS_Wire& aWire = thePolyline->Wire();
+ if( !aWire.IsNull() )
{
- const SplitData& anOutputSplitData = anOutputIter.next();
+ BRepBuilderAPI_MakeFace aMakeFace( aWire, Standard_True );
+ aMakeFace.Build();
+ if( aMakeFace.IsDone() )
+ {
+ SplitData aBoundarySplitData( aMakeFace.Face(), "" );
+
+ SplitDataList aCutSplitDataList;
+ SplitDataListIterator anOutputIter( anOutputSplitDataList );
+ while( anOutputIter.hasNext() )
+ {
+ const SplitData& anOutputSplitData = anOutputIter.next();
- SplitData aData1Subtracted, aData2Subtracted, aDataIntersected;
- if( SplitTwoData( anOutputSplitData, aBoundarySplitData,
- aData1Subtracted, aData2Subtracted, aDataIntersected ) )
- aCutSplitDataList.append( aDataIntersected );
+ SplitData aData1Subtracted, aData2Subtracted, aDataIntersected;
+ if( SplitTwoData( anOutputSplitData, aBoundarySplitData,
+ aData1Subtracted, aData2Subtracted, aDataIntersected ) )
+ aCutSplitDataList.append( aDataIntersected );
+ }
+ anOutputSplitDataList = aCutSplitDataList;
+ }
}
- anOutputSplitDataList = aCutSplitDataList;
}
// Step 3. Extract the separate regions.
- //printf( "Step 3\n" );
SplitDataList anExtractedSplitDataList;
SplitDataListIterator anOutputIter( anOutputSplitDataList );
while( anOutputIter.hasNext() )
SplitData& theData2Subtracted,
SplitData& theDataIntersected )
{
- const QPainterPath& aPath1 = theData1.Path;
- const QPainterPath& aPath2 = theData2.Path;
+ const TopoDS_Shape& aShape1 = theData1.Shape;
+ const TopoDS_Shape& aShape2 = theData2.Shape;
const QStringList& aZoneNames1 = theData1.ZoneNames;
const QStringList& aZoneNames2 = theData2.ZoneNames;
- //printPath( "aPath1", aPath1, aZoneNames1 );
- //printPath( "aPath2", aPath2, aZoneNames2 );
-
- QPainterPath aPathIntersected = aPath1.intersected( aPath2 );
- aPathIntersected.closeSubpath();
- //printPath( "aPathIntersected", aPathIntersected );
- if( aPathIntersected.isEmpty() )
+ BRepAlgoAPI_Common aCommon( aShape1, aShape2 );
+ TopoDS_Shape aCommonShape = aCommon.Shape();
+ if( aCommonShape.IsNull() )
{
theData1Subtracted = theData1;
theData2Subtracted = theData2;
return false;
}
- QPainterPath aPath1Subtracted = aPath1.subtracted( aPath2 );
- //printPath( "aPath1Subtracted", aPath1Subtracted );
- theData1Subtracted = SplitData( aPath1Subtracted, aZoneNames1 );
+ BRepAlgoAPI_Cut aCut1( aShape1, aShape2 );
+ TopoDS_Shape aCut1Shape = aCut1.Shape();
- QPainterPath aPath2Subtracted = aPath2.subtracted( aPath1 );
- //printPath( "aPath2Subtracted", aPath2Subtracted );
- theData2Subtracted = SplitData( aPath2Subtracted, aZoneNames2 );
+ BRepAlgoAPI_Cut aCut2( aShape2, aShape1 );
+ TopoDS_Shape aCut2Shape = aCut2.Shape();
- theDataIntersected = SplitData( aPathIntersected, aZoneNames1 + aZoneNames2 );
+ theData1Subtracted = SplitData( aCut1Shape, aZoneNames1 );
+ theData2Subtracted = SplitData( aCut2Shape, aZoneNames2 );
+ theDataIntersected = SplitData( aCommonShape, aZoneNames1 + aZoneNames2 );
return true;
}
HYDROGUI_SplitZonesTool::ExtractSeparateData( const SplitData& theData )
{
SplitDataList aSplitDataList;
-
- const QPainterPath& aBasePath = theData.Path;
- const QStringList& aBaseZoneNames = theData.ZoneNames;
-
- QList<QPainterPath> aPathList;
- for( int i = 0, n = aBasePath.elementCount(); i < n; i++ )
+ TopExp_Explorer anExp( theData.Shape, TopAbs_FACE );
+ for( ; anExp.More(); anExp.Next() )
{
- const QPainterPath::Element anElement = aBasePath.elementAt( i );
- switch( anElement.type )
+ TopoDS_Shape aShape = anExp.Current();
+ if( aShape.ShapeType() == TopAbs_FACE )
{
- case QPainterPath::MoveToElement:
- aPathList.append( QPainterPath( QPointF( anElement.x, anElement.y ) ) );
- break;
- case QPainterPath::LineToElement:
- if( !aPathList.isEmpty() )
- {
- QPainterPath& aPath = aPathList.last();
- aPath.lineTo( anElement.x, anElement.y );
- }
- break;
- case QPainterPath::CurveToElement: // currently not supported
- default:
- break;
- }
- }
-
- // check the hole case
- if( aPathList.size() == 2 )
- {
- const QPainterPath& aPath1 = aPathList.first();
- const QPainterPath& aPath2 = aPathList.last();
- if( aPath1.contains( aPath2 ) || aPath2.contains( aPath1 ) )
- {
- aSplitDataList.append( theData );
- return aSplitDataList;
+ TopoDS_Face aFace = TopoDS::Face( aShape );
+ if( !aFace.IsNull() )
+ {
+ SplitData aSplitData( aFace, theData.ZoneNames );
+ aSplitDataList.append( aSplitData );
+ }
}
}
-
- QListIterator<QPainterPath> anIter( aPathList );
- while( anIter.hasNext() )
- {
- QPainterPath aPath = anIter.next();
- aPath.closeSubpath();
- //printPath( "aPath", aPath );
- aSplitDataList.append( SplitData( aPath, aBaseZoneNames ) );
- }
return aSplitDataList;
}
#include <HYDROData_Object.h>
-#include <QPainterPath>
+#include <TopoDS_Face.hxx>
+
#include <QStringList>
class Handle(HYDROData_Polyline);
public:
struct SplitData
{
- QPainterPath Path;
+ TopoDS_Shape Shape;
QStringList ZoneNames;
SplitData() {}
- SplitData( const QPainterPath& thePath,
+ SplitData( const TopoDS_Shape& theShape,
const QStringList& theZoneNames ) :
- Path( thePath ), ZoneNames( theZoneNames ) {}
+ Shape( theShape ), ZoneNames( theZoneNames ) {}
- SplitData( const QPainterPath& thePath,
+ SplitData( const TopoDS_Shape& theShape,
const QString& theZoneName ) :
- Path( thePath ), ZoneNames( theZoneName ) {}
+ Shape( theShape ), ZoneNames( theZoneName ) {}
+
+ TopoDS_Face Face() const;
};
typedef QList <SplitData> SplitDataList;
#include <LightApp_Application.h>
#include <LightApp_UpdateFlags.h>
+#include <TopoDS_Wire.hxx>
+
HYDROGUI_ZoneOp::HYDROGUI_ZoneOp( HYDROGUI_Module* theModule,
const bool theIsEdit )
: HYDROGUI_Operation( theModule ),
if ( !aPanel )
return;
- QPainterPath aPath;
+ TopoDS_Wire aWire;
Handle(HYDROData_Polyline) aPolyline = Handle(HYDROData_Polyline)::DownCast(
HYDROGUI_Tool::FindObjectByName( module(), thePolylineName, KIND_POLYLINE ) );
if ( !aPolyline.IsNull() )
{
- aPath = aPolyline->painterPath();
+ aWire = aPolyline->Wire();
}
LightApp_Application* anApp = module()->getApp();
myPreviewPrs->setFillingColor( aPanel->getFillingColor(), false );
myPreviewPrs->setBorderColor( aPanel->getBorderColor(), false );
- myPreviewPrs->setPath( aPath, true );
+ myPreviewPrs->setWire( aWire, true );
}
void HYDROGUI_ZoneOp::onLastViewClosed( SUIT_ViewManager* theViewManager )
#include <HYDROData_Zone.h>
-#include <QPainterPath>
-
class OCCViewer_ViewManager;
class SUIT_ViewManager;
OCCViewer_ViewManager* myPreviewViewManager;
HYDROGUI_Shape* myPreviewPrs;
-
- QPainterPath myZonePath;
};
#endif
#pragma comment (lib , "TKMath.lib")
// Application Framework
+#pragma comment (lib , "TKBO.lib")
+#pragma comment (lib , "TKBRep.lib")
+#pragma comment (lib , "TKCAF.lib")
#pragma comment (lib , "TKCDF.lib")
#pragma comment (lib , "TKG3d.lib")
#pragma comment (lib , "TKGeomAlgo.lib")
#pragma comment (lib , "TKGeomBase.lib")
#pragma comment (lib , "TKLCAF.lib")
-#pragma comment (lib , "TKV3d.lib")
-#pragma comment (lib , "TKBrep.lib")
#pragma comment (lib , "TKTopAlgo.lib")
+#pragma comment (lib , "TKV3d.lib")