From 6f6d31e902b53b4fb66624121d0f723fd67d85f8 Mon Sep 17 00:00:00 2001 From: stv Date: Fri, 26 Jun 2015 10:56:18 +0300 Subject: [PATCH] #571 - Land Cover: calculation of Strickler coefficient #572 - Extraction of polylines #563 - Strickler table: dump to Python (bug fixing) #599 - Incorrect behavior of 'eyes' in Object browser after reloading python script --- .../HYDROGUI_PolylineExtractionOp.cxx | 181 ++++++++++++++++++ src/HYDROGUI/HYDROGUI_PolylineExtractionOp.h | 51 +++++ 2 files changed, 232 insertions(+) create mode 100644 src/HYDROGUI/HYDROGUI_PolylineExtractionOp.cxx create mode 100644 src/HYDROGUI/HYDROGUI_PolylineExtractionOp.h diff --git a/src/HYDROGUI/HYDROGUI_PolylineExtractionOp.cxx b/src/HYDROGUI/HYDROGUI_PolylineExtractionOp.cxx new file mode 100644 index 00000000..4a758cf0 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_PolylineExtractionOp.cxx @@ -0,0 +1,181 @@ +// Copyright (C) 2014-2015 EDF-R&D +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "HYDROGUI_PolylineExtractionOp.h" + +#include + +#include "HYDROGUI_Module.h" +#include "HYDROGUI_Operations.h" +#include "HYDROGUI_Tool.h" +#include "HYDROGUI_UpdateFlags.h" + +#include +#include +#include +#include + +#include +#include + +#include +#include + +#include + +HYDROGUI_PolylineExtractionOp::HYDROGUI_PolylineExtractionOp( HYDROGUI_Module* theModule ) +: HYDROGUI_Operation( theModule ) +{ + setName( tr( "POLYLINE_EXTRACTION" ) ); +} + +HYDROGUI_PolylineExtractionOp::~HYDROGUI_PolylineExtractionOp() +{ +} + +void HYDROGUI_PolylineExtractionOp::startOperation() +{ + HYDROGUI_Operation::startOperation(); + + int anUpdateFlags = UF_ObjBrowser | UF_Model; + HYDROGUI_Module* aModule = module(); + + HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( aModule ); + if ( aSeq.IsEmpty() ) + return; + + for ( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ ) + { + Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex ); + if ( anObject.IsNull() ) + continue; + + ShapeMap aMap; + + switch ( anObject->GetKind() ) + { + case KIND_STREAM: + aMap = extract( Handle(HYDROData_Stream)::DownCast( anObject ) ); + break; + case KIND_DIGUE: + case KIND_CHANNEL: + aMap = extract( Handle(HYDROData_Channel)::DownCast( anObject ) ); + break; + case KIND_OBSTACLE: + aMap = extract( Handle(HYDROData_Obstacle)::DownCast( anObject ) ); + break; + } + + startDocOperation(); + + for ( ShapeMap::Iterator it( aMap ); it.More(); it.Next() ) + { + TopoDS_Shape aLine = it.Key(); + QString aName = QString( "%1_%2" ).arg( anObject->GetName() ).arg( it.Value() ); + if ( !HYDROGUI_Tool::FindObjectByName( aModule, aName ).IsNull() ) + { + int num = 1; + while ( !HYDROGUI_Tool::FindObjectByName( aModule, aName + QString( "_%1" ).arg( num ) ).IsNull() ) + num++; + + aName += QString( "_%1" ).arg( num ); + } + + Handle(HYDROData_PolylineXY) aPolylineObj = Handle(HYDROData_PolylineXY)::DownCast( doc()->CreateObject( KIND_POLYLINEXY ) ); + if ( !aPolylineObj.IsNull() ) + { + aPolylineObj->SetName( aName ); + aPolylineObj->ImportShape( aLine ); + aPolylineObj->Update(); + } + } + + commitDocOperation(); + } + + aModule->update( anUpdateFlags ); + + commit(); +} + +HYDROGUI_PolylineExtractionOp::ShapeMap HYDROGUI_PolylineExtractionOp::extract( const Handle(HYDROData_Stream)& theStream ) +{ + ShapeMap aMap; + if ( !theStream.IsNull() ) + { + aMap.Bind( theStream->GetLeftShape(), "Left bank" ); + aMap.Bind( theStream->GetRightShape(), "Right bank" ); + + HYDROData_SequenceOfObjects aProfiles = theStream->GetProfiles(); + for ( int i = 1; i <= aProfiles.Length(); i++ ) + { + Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast( aProfiles.Value( i ) ); + aMap.Bind( aProfile->GetTopShape(), aProfile->GetName() ); + } + } + return aMap; +} + +HYDROGUI_PolylineExtractionOp::ShapeMap HYDROGUI_PolylineExtractionOp::extract( const Handle(HYDROData_Channel)& aChannel ) +{ + ShapeMap aMap; + if ( !aChannel.IsNull() ) + { + HYDROData_SequenceOfObjects aGroups = aChannel->GetGroups(); + int aNum = qMin( aGroups.Length(), 2 ); + for ( int i = 1; i <= aNum; i++ ) + { + Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast( aGroups.Value( i ) ); + TopTools_SequenceOfShape aShapes; + aGroup->GetShapes( aShapes ); + if ( !aShapes.IsEmpty() ) + { + TopoDS_Wire aWire; + BRep_Builder aBuilder; + aBuilder.MakeWire( aWire ); + + for ( int s = 1; s <= aShapes.Length(); s++ ) + aBuilder.Add( aWire, aShapes.Value( s ) ); + aMap.Bind( aWire, i > 1 ? "Right bank" : "Left bank" ); + } + } + } + return aMap; +} + +HYDROGUI_PolylineExtractionOp::ShapeMap HYDROGUI_PolylineExtractionOp::extract( const Handle(HYDROData_Obstacle)& theObstacle ) +{ + ShapeMap aMap; + if ( !theObstacle.IsNull() ) + { + TopoDS_Wire aWire; + BRep_Builder aBuilder; + aBuilder.MakeWire( aWire ); + HYDROData_SequenceOfObjects aGroups = theObstacle->GetGroups(); + for ( int i = 1; i <= aGroups.Length(); i++ ) + { + Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast( aGroups.Value( i ) ); + TopTools_SequenceOfShape aShapes; + aGroup->GetShapes( aShapes ); + for ( int s = 1; s <= aShapes.Length(); s++ ) + aBuilder.Add( aWire, aShapes.Value( s ) ); + } + aMap.Bind( aWire, "Contour" ); + } + return aMap; +} diff --git a/src/HYDROGUI/HYDROGUI_PolylineExtractionOp.h b/src/HYDROGUI/HYDROGUI_PolylineExtractionOp.h new file mode 100644 index 00000000..72fbc6fc --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_PolylineExtractionOp.h @@ -0,0 +1,51 @@ +// Copyright (C) 2014-2015 EDF-R&D +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef HYDROGUI_POLYLINEEXTRACTIONOP_H +#define HYDROGUI_POLYLINEEXTRACTIONOP_H + +#include "HYDROGUI_Operation.h" + +#include +#include +#include + +#include + +class HYDROGUI_PolylineExtractionOp : public HYDROGUI_Operation +{ + Q_OBJECT + +public: + + HYDROGUI_PolylineExtractionOp( HYDROGUI_Module* theModule ); + virtual ~HYDROGUI_PolylineExtractionOp(); + +protected: + virtual void startOperation(); + +private: + typedef NCollection_DataMap ShapeMap; + +private: + ShapeMap extract( const Handle(HYDROData_Stream)& ); + ShapeMap extract( const Handle(HYDROData_Channel)& ); + ShapeMap extract( const Handle(HYDROData_Obstacle)& ); +}; + +#endif -- 2.39.2