1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "HYDROGUI_PolylineExtractionOp.h"
21 #include <GraphicsView_Viewer.h>
23 #include "HYDROGUI_Module.h"
24 #include "HYDROGUI_Operations.h"
25 #include "HYDROGUI_Tool.h"
26 #include "HYDROGUI_UpdateFlags.h"
28 #include <HYDROData_Profile.h>
29 #include <HYDROData_Document.h>
30 #include <HYDROData_PolylineXY.h>
31 #include <HYDROData_ShapesGroup.h>
33 #include <LightApp_Application.h>
34 #include <LightApp_Displayer.h>
36 #include <OCCViewer_ViewModel.h>
37 #include <OCCViewer_ViewManager.h>
39 #include <BRep_Builder.hxx>
41 HYDROGUI_PolylineExtractionOp::HYDROGUI_PolylineExtractionOp( HYDROGUI_Module* theModule )
42 : HYDROGUI_Operation( theModule )
44 setName( tr( "POLYLINE_EXTRACTION" ) );
47 HYDROGUI_PolylineExtractionOp::~HYDROGUI_PolylineExtractionOp()
51 void HYDROGUI_PolylineExtractionOp::startOperation()
53 HYDROGUI_Operation::startOperation();
55 int anUpdateFlags = UF_ObjBrowser | UF_Model;
56 HYDROGUI_Module* aModule = module();
58 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( aModule );
62 for ( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
64 Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex );
65 if ( anObject.IsNull() )
70 switch ( anObject->GetKind() )
73 aList = extract( Handle(HYDROData_Stream)::DownCast( anObject ) );
77 aList = extract( Handle(HYDROData_Channel)::DownCast( anObject ) );
80 aList = extract( Handle(HYDROData_Obstacle)::DownCast( anObject ) );
86 for ( ShapeInfoList::const_iterator it = aList.begin(); it != aList.end(); ++it )
88 const ShapeInfo& inf = *it;
89 TopoDS_Shape aLine = inf.shape();
90 QString aName = QString( "%1_%2" ).arg( anObject->GetName() ).arg( inf.name() );
91 if ( !HYDROGUI_Tool::FindObjectByName( aModule, aName ).IsNull() )
94 while ( !HYDROGUI_Tool::FindObjectByName( aModule, aName + QString( "_%1" ).arg( num ) ).IsNull() )
97 aName += QString( "_%1" ).arg( num );
100 Handle(HYDROData_PolylineXY) aPolylineObj = Handle(HYDROData_PolylineXY)::DownCast( doc()->CreateObject( KIND_POLYLINEXY ) );
101 if ( !aPolylineObj.IsNull() )
103 aPolylineObj->SetName( aName );
104 aPolylineObj->ImportShape( aLine );
105 aPolylineObj->Update();
109 commitDocOperation();
112 aModule->update( anUpdateFlags );
117 HYDROGUI_PolylineExtractionOp::ShapeInfoList HYDROGUI_PolylineExtractionOp::extract( const Handle(HYDROData_Stream)& theStream ) const
120 if ( !theStream.IsNull() )
122 aList.append( ShapeInfo( theStream->GetLeftShape(), QString( "Left bank" ) ) );
123 aList.append( ShapeInfo( theStream->GetRightShape(), QString( "Right bank" ) ) );
125 HYDROData_SequenceOfObjects aProfiles = theStream->GetProfiles();
126 for ( int i = 1; i <= aProfiles.Length(); i++ )
128 Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast( aProfiles.Value( i ) );
129 aList.append( ShapeInfo( aProfile->GetTopShape(), QString( "Profile_%1" ).arg( i ) ) );
135 HYDROGUI_PolylineExtractionOp::ShapeInfoList HYDROGUI_PolylineExtractionOp::extract( const Handle(HYDROData_Channel)& aChannel ) const
138 if ( !aChannel.IsNull() )
140 HYDROData_SequenceOfObjects aGroups = aChannel->GetGroups();
141 int aNum = qMin( aGroups.Length(), 2 );
142 for ( int i = 1; i <= aNum; i++ )
144 Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast( aGroups.Value( i ) );
145 TopTools_SequenceOfShape aShapes;
146 aGroup->GetShapes( aShapes );
147 if ( !aShapes.IsEmpty() )
150 BRep_Builder aBuilder;
151 aBuilder.MakeWire( aWire );
153 for ( int s = 1; s <= aShapes.Length(); s++ )
154 aBuilder.Add( aWire, aShapes.Value( s ) );
155 aList.append( ShapeInfo( aWire, i > 1 ? "Right bank" : "Left bank" ) );
162 HYDROGUI_PolylineExtractionOp::ShapeInfoList HYDROGUI_PolylineExtractionOp::extract( const Handle(HYDROData_Obstacle)& theObstacle ) const
165 if ( !theObstacle.IsNull() )
168 BRep_Builder aBuilder;
169 aBuilder.MakeWire( aWire );
170 HYDROData_SequenceOfObjects aGroups = theObstacle->GetGroups();
171 for ( int i = 1; i <= aGroups.Length(); i++ )
173 Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast( aGroups.Value( i ) );
174 TopTools_SequenceOfShape aShapes;
175 aGroup->GetShapes( aShapes );
176 for ( int s = 1; s <= aShapes.Length(); s++ )
177 aBuilder.Add( aWire, aShapes.Value( s ) );
179 aList.append( ShapeInfo( aWire, QString( "Contour" ) ) );