From: ouv Date: Thu, 26 Sep 2013 12:55:58 +0000 (+0000) Subject: HYDRO feature 10: Creation/edition of the calculation case (T 1.12). X-Git-Tag: BR_hydro_v_0_3~108 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=f664563df96e1f99e099bc90a1088533e6a018b0;p=modules%2Fhydro.git HYDRO feature 10: Creation/edition of the calculation case (T 1.12). --- diff --git a/src/HYDROData/HYDROData_Domain.h b/src/HYDROData/HYDROData_Domain.h index 00c24906..ac1a9101 100644 --- a/src/HYDROData/HYDROData_Domain.h +++ b/src/HYDROData/HYDROData_Domain.h @@ -4,6 +4,8 @@ #include +#include + #include #include @@ -113,6 +115,11 @@ public: */ //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; diff --git a/src/HYDROData/HYDROData_Polyline.cxx b/src/HYDROData/HYDROData_Polyline.cxx index fb723700..ae0330ed 100755 --- a/src/HYDROData/HYDROData_Polyline.cxx +++ b/src/HYDROData/HYDROData_Polyline.cxx @@ -1,8 +1,13 @@ #include #include +#include + #include +#include +#include +#include #include #include #include @@ -12,6 +17,11 @@ #include #include #include +#include +#include +#include +#include +#include #include @@ -199,6 +209,8 @@ void HYDROData_Polyline::setPolylineData( const PolylineData& theSections ) aPtr++; } } + + UpdateWire( theSections ); } /** @@ -304,29 +316,122 @@ void HYDROData_Polyline::removeAll() } /** - * 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 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 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 ); +} diff --git a/src/HYDROData/HYDROData_Polyline.h b/src/HYDROData/HYDROData_Polyline.h index 3906ac53..4f9e4008 100755 --- a/src/HYDROData/HYDROData_Polyline.h +++ b/src/HYDROData/HYDROData_Polyline.h @@ -9,6 +9,8 @@ #include #include +class TopoDS_Wire; + DEFINE_STANDARD_HANDLE(HYDROData_Polyline, HYDROData_Object) struct PolylineSection @@ -45,7 +47,8 @@ protected: DataTag_SectionsName, DataTag_SectionsClosed, DataTag_SectionsSize, - DataTag_SectionsType + DataTag_SectionsType, + DataTag_Wire }; public: @@ -101,12 +104,27 @@ 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: diff --git a/src/HYDROData/HYDROData_Region.cxx b/src/HYDROData/HYDROData_Region.cxx index 2550de1f..16680653 100644 --- a/src/HYDROData/HYDROData_Region.cxx +++ b/src/HYDROData/HYDROData_Region.cxx @@ -1,6 +1,10 @@ #include "HYDROData_Region.h" +#include +#include +#include + #include #define PYTHON_REGION_ID "KIND_REGION" @@ -18,6 +22,20 @@ HYDROData_Region::~HYDROData_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 ); diff --git a/src/HYDROData/HYDROData_Region.h b/src/HYDROData/HYDROData_Region.h index 2cc3f0e1..23cd0d62 100644 --- a/src/HYDROData/HYDROData_Region.h +++ b/src/HYDROData/HYDROData_Region.h @@ -21,6 +21,7 @@ protected: enum DataTag { DataTag_First = HYDROData_Domain::DataTag_First + 100, ///< first tag, to reserve + DataTag_Face }; public: @@ -31,6 +32,16 @@ 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; diff --git a/src/HYDROData/HYDROData_Zone.cxx b/src/HYDROData/HYDROData_Zone.cxx index 15246161..3af90622 100644 --- a/src/HYDROData/HYDROData_Zone.cxx +++ b/src/HYDROData/HYDROData_Zone.cxx @@ -6,7 +6,9 @@ #include "HYDROData_Polyline.h" #include "HYDROData_Iterator.h" +#include #include +#include #include #include @@ -54,17 +56,21 @@ void HYDROData_Zone::RemovePolyline() 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 diff --git a/src/HYDROData/HYDROData_Zone.h b/src/HYDROData/HYDROData_Zone.h index 4bbe43b5..b9a86cbf 100644 --- a/src/HYDROData/HYDROData_Zone.h +++ b/src/HYDROData/HYDROData_Zone.h @@ -4,7 +4,6 @@ #include -#include class Handle(HYDROData_Polyline); DEFINE_STANDARD_HANDLE(HYDROData_Zone, HYDROData_Domain) @@ -63,10 +62,9 @@ public: //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: diff --git a/src/HYDROData/HYDROOperations_BSpline.cxx b/src/HYDROData/HYDROOperations_BSpline.cxx index 376490da..d2dd0176 100644 --- a/src/HYDROData/HYDROOperations_BSpline.cxx +++ b/src/HYDROData/HYDROOperations_BSpline.cxx @@ -6,12 +6,13 @@ #include HYDROOperations_BSpline::HYDROOperations_BSpline( - QList& thePoints) + const QList& 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::iterator aListIter = thePoints.begin(); + QList::const_iterator aListIter = thePoints.begin(); for (int ind = 1; ind <= aLen; ind++) { gp_Pnt aPnt(gp::Origin()); aPnt.SetX(*aListIter); @@ -21,7 +22,7 @@ HYDROOperations_BSpline::HYDROOperations_BSpline( 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(); diff --git a/src/HYDROData/HYDROOperations_BSpline.h b/src/HYDROData/HYDROOperations_BSpline.h index 47c3f305..0021af19 100644 --- a/src/HYDROData/HYDROOperations_BSpline.h +++ b/src/HYDROData/HYDROOperations_BSpline.h @@ -20,7 +20,9 @@ public: //! 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& thePoints); + //! \param theIsClosed flag indicating that the result spline should be closed + HYDROOperations_BSpline(const QList& thePoints, + const bool theIsClosed); //! Returns the BSpline curve passing through the points //! \returns Null if Computation of BSpline was failed diff --git a/src/HYDROGUI/HYDROGUI_AISCurve.cxx b/src/HYDROGUI/HYDROGUI_AISCurve.cxx index 8899eafd..67265afd 100755 --- a/src/HYDROGUI/HYDROGUI_AISCurve.cxx +++ b/src/HYDROGUI/HYDROGUI_AISCurve.cxx @@ -1,14 +1,20 @@ #include "HYDROGUI_AISCurve.h" -#include "CurveCreator_Curve.hxx" +#include + +#include #include #include - +#include +#include +#include +#include #include #include - -#include +#include +#include +#include HYDROGUI_AISCurveSection::HYDROGUI_AISCurveSection( Handle_AIS_InteractiveContext theContext, CurveCreator_Curve* theCurve, int theSection) : @@ -40,44 +46,74 @@ void HYDROGUI_AISCurveSection::highlight( bool isHL ) 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 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 ); + } } } diff --git a/src/HYDROGUI/HYDROGUI_CalculationOp.cxx b/src/HYDROGUI/HYDROGUI_CalculationOp.cxx index 3e1a5dc8..6e8aa189 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationOp.cxx +++ b/src/HYDROGUI/HYDROGUI_CalculationOp.cxx @@ -116,8 +116,7 @@ void HYDROGUI_CalculationOp::startOperation() continue; Region aRegion; - // aRegion.SplitData.Path = aSplitZone->GetPainterPath(); - // aRegion.SplitData.ZoneNames ??? + aRegion.SplitData.Shape = aDataRegion->Face(); aRegion.FillingColor = aDataRegion->GetFillingColor(); aRegion.BorderColor = aDataRegion->GetBorderColor(); @@ -251,6 +250,8 @@ bool HYDROGUI_CalculationOp::processApply( int& theUpdateFlags, continue; // Fill the zone data + aDataRegion->SetFace( aRegion.SplitData.Face() ); + aDataRegion->SetName( aRegion.RegionName ); aDataRegion->SetBorderColor( aRegion.BorderColor ); aDataRegion->SetFillingColor( aRegion.FillingColor ); @@ -362,7 +363,7 @@ void HYDROGUI_CalculationOp::createPreview() 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 diff --git a/src/HYDROGUI/HYDROGUI_Module.h b/src/HYDROGUI/HYDROGUI_Module.h index fde4689c..32e1162e 100644 --- a/src/HYDROGUI/HYDROGUI_Module.h +++ b/src/HYDROGUI/HYDROGUI_Module.h @@ -125,8 +125,6 @@ protected slots: void onViewPortMouseEvent( QGraphicsSceneMouseEvent* ); - void onTestSplit(); // ouv: tmp, to delete - private: void updateGV( const bool theIsInit = false, const bool theIsForced = false ); diff --git a/src/HYDROGUI/HYDROGUI_Operations.cxx b/src/HYDROGUI/HYDROGUI_Operations.cxx index 7bf1c895..706d9b75 100644 --- a/src/HYDROGUI/HYDROGUI_Operations.cxx +++ b/src/HYDROGUI/HYDROGUI_Operations.cxx @@ -137,10 +137,6 @@ void HYDROGUI_Module::createMenus() 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() @@ -174,10 +170,6 @@ void HYDROGUI_Module::createUndoRedoActions() 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() @@ -322,100 +314,3 @@ LightApp_Operation* HYDROGUI_Module::createOperation( const int theId ) const return anOp; } - -//----------------------------------------------------------------------------- -// Test splitting -//----------------------------------------------------------------------------- -#include -#include -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 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 ); -} diff --git a/src/HYDROGUI/HYDROGUI_Operations.h b/src/HYDROGUI/HYDROGUI_Operations.h index e0cf2f3c..c8b8309f 100644 --- a/src/HYDROGUI/HYDROGUI_Operations.h +++ b/src/HYDROGUI/HYDROGUI_Operations.h @@ -70,8 +70,6 @@ enum OperationId ShowAllId, HideId, HideAllId, - - TestSplitId }; #endif diff --git a/src/HYDROGUI/HYDROGUI_PrsZoneDriver.cxx b/src/HYDROGUI/HYDROGUI_PrsZoneDriver.cxx index 5edfaa1d..6d6aca2e 100644 --- a/src/HYDROGUI/HYDROGUI_PrsZoneDriver.cxx +++ b/src/HYDROGUI/HYDROGUI_PrsZoneDriver.cxx @@ -57,7 +57,8 @@ bool HYDROGUI_PrsZoneDriver::Update( const Handle(HYDROData_Object)& theObj, aPrsZone->setFillingColor( aZone->GetFillingColor() ); aPrsZone->setBorderColor( aZone->GetBorderColor() ); - aPrsZone->setPath( aZone->GetPainterPath() ); + // ouv: the method is no more + //aPrsZone->setPath( aZone->GetPainterPath() ); aPrsZone->compute(); diff --git a/src/HYDROGUI/HYDROGUI_Shape.cxx b/src/HYDROGUI/HYDROGUI_Shape.cxx index be595d23..b973cefd 100644 --- a/src/HYDROGUI/HYDROGUI_Shape.cxx +++ b/src/HYDROGUI/HYDROGUI_Shape.cxx @@ -47,7 +47,6 @@ 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 ) @@ -62,20 +61,20 @@ HYDROGUI_Shape::~HYDROGUI_Shape() 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 ) @@ -97,32 +96,26 @@ bool HYDROGUI_Shape::isHighlighted() const 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 ) { @@ -157,113 +150,15 @@ QColor HYDROGUI_Shape::getHighlightColor() const 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 ); @@ -284,11 +179,11 @@ void HYDROGUI_Shape::buildShape() 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 ); } } } @@ -321,7 +216,7 @@ void HYDROGUI_Shape::updateShape( const bool theIsForce ) if ( !theIsForce || !myContext ) return; - myContext->Display( myShape ); + myContext->Display( myShape, theIsForce ); } QColor HYDROGUI_Shape::getActiveColor() const diff --git a/src/HYDROGUI/HYDROGUI_Shape.h b/src/HYDROGUI/HYDROGUI_Shape.h index 3adfec17..885e23d0 100644 --- a/src/HYDROGUI/HYDROGUI_Shape.h +++ b/src/HYDROGUI/HYDROGUI_Shape.h @@ -26,8 +26,10 @@ #include #include +#include +#include + #include -#include class BRepBuilderAPI_MakeFace; class BRepBuilderAPI_MakeWire; @@ -40,19 +42,17 @@ public: ~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 ); @@ -74,22 +74,13 @@ private: 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; diff --git a/src/HYDROGUI/HYDROGUI_SplitZonesTool.cxx b/src/HYDROGUI/HYDROGUI_SplitZonesTool.cxx index f8a19c98..1a20f39d 100644 --- a/src/HYDROGUI/HYDROGUI_SplitZonesTool.cxx +++ b/src/HYDROGUI/HYDROGUI_SplitZonesTool.cxx @@ -25,36 +25,19 @@ #include #include -void printPath( const QString& thePathName, - const QPainterPath& thePath, - const QStringList& theZonesList = QStringList() ) +#include +#include +#include +#include +#include +#include +#include + +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 @@ -70,13 +53,12 @@ HYDROGUI_SplitZonesTool::SplitZones( const HYDROData_SequenceOfObjects& theZoneL 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() ) { @@ -114,28 +96,34 @@ HYDROGUI_SplitZonesTool::SplitZones( const HYDROData_SequenceOfObjects& theZoneL } // 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() ) @@ -152,34 +140,30 @@ bool HYDROGUI_SplitZonesTool::SplitTwoData( const SplitData& theData1, 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; } @@ -188,51 +172,19 @@ HYDROGUI_SplitZonesTool::SplitDataList HYDROGUI_SplitZonesTool::ExtractSeparateData( const SplitData& theData ) { SplitDataList aSplitDataList; - - const QPainterPath& aBasePath = theData.Path; - const QStringList& aBaseZoneNames = theData.ZoneNames; - - QList 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 anIter( aPathList ); - while( anIter.hasNext() ) - { - QPainterPath aPath = anIter.next(); - aPath.closeSubpath(); - //printPath( "aPath", aPath ); - aSplitDataList.append( SplitData( aPath, aBaseZoneNames ) ); - } return aSplitDataList; } diff --git a/src/HYDROGUI/HYDROGUI_SplitZonesTool.h b/src/HYDROGUI/HYDROGUI_SplitZonesTool.h index 0f68d15f..ca74d3c5 100644 --- a/src/HYDROGUI/HYDROGUI_SplitZonesTool.h +++ b/src/HYDROGUI/HYDROGUI_SplitZonesTool.h @@ -25,7 +25,8 @@ #include -#include +#include + #include class Handle(HYDROData_Polyline); @@ -40,18 +41,20 @@ class HYDROGUI_SplitZonesTool 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 SplitDataList; diff --git a/src/HYDROGUI/HYDROGUI_ZoneOp.cxx b/src/HYDROGUI/HYDROGUI_ZoneOp.cxx index e2c95ab1..25cefb60 100644 --- a/src/HYDROGUI/HYDROGUI_ZoneOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ZoneOp.cxx @@ -39,6 +39,8 @@ #include #include +#include + HYDROGUI_ZoneOp::HYDROGUI_ZoneOp( HYDROGUI_Module* theModule, const bool theIsEdit ) : HYDROGUI_Operation( theModule ), @@ -256,13 +258,13 @@ void HYDROGUI_ZoneOp::onCreatePreview( const QString& thePolylineName ) 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(); @@ -300,7 +302,7 @@ void HYDROGUI_ZoneOp::onCreatePreview( const QString& thePolylineName ) 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 ) diff --git a/src/HYDROGUI/HYDROGUI_ZoneOp.h b/src/HYDROGUI/HYDROGUI_ZoneOp.h index 4677e5d6..f1419481 100644 --- a/src/HYDROGUI/HYDROGUI_ZoneOp.h +++ b/src/HYDROGUI/HYDROGUI_ZoneOp.h @@ -27,8 +27,6 @@ #include -#include - class OCCViewer_ViewManager; class SUIT_ViewManager; @@ -68,8 +66,6 @@ private: OCCViewer_ViewManager* myPreviewViewManager; HYDROGUI_Shape* myPreviewPrs; - - QPainterPath myZonePath; }; #endif diff --git a/src/Link/Link_OCC.cxx b/src/Link/Link_OCC.cxx index ebbcdb3f..54e51a7d 100644 --- a/src/Link/Link_OCC.cxx +++ b/src/Link/Link_OCC.cxx @@ -10,12 +10,14 @@ #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")