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 aMap = extract( Handle(HYDROData_Stream)::DownCast( anObject ) );
77 aMap = extract( Handle(HYDROData_Channel)::DownCast( anObject ) );
80 aMap = extract( Handle(HYDROData_Obstacle)::DownCast( anObject ) );
86 for ( ShapeMap::Iterator it( aMap ); it.More(); it.Next() )
88 TopoDS_Shape aLine = it.Key();
89 QString aName = QString( "%1_%2" ).arg( anObject->GetName() ).arg( it.Value() );
90 if ( !HYDROGUI_Tool::FindObjectByName( aModule, aName ).IsNull() )
93 while ( !HYDROGUI_Tool::FindObjectByName( aModule, aName + QString( "_%1" ).arg( num ) ).IsNull() )
96 aName += QString( "_%1" ).arg( num );
99 Handle(HYDROData_PolylineXY) aPolylineObj = Handle(HYDROData_PolylineXY)::DownCast( doc()->CreateObject( KIND_POLYLINEXY ) );
100 if ( !aPolylineObj.IsNull() )
102 aPolylineObj->SetName( aName );
103 aPolylineObj->ImportShape( aLine );
104 aPolylineObj->Update();
108 commitDocOperation();
111 aModule->update( anUpdateFlags );
116 HYDROGUI_PolylineExtractionOp::ShapeMap HYDROGUI_PolylineExtractionOp::extract( const Handle(HYDROData_Stream)& theStream )
119 if ( !theStream.IsNull() )
121 aMap.Bind( theStream->GetLeftShape(), "Left bank" );
122 aMap.Bind( theStream->GetRightShape(), "Right bank" );
124 HYDROData_SequenceOfObjects aProfiles = theStream->GetProfiles();
125 for ( int i = 1; i <= aProfiles.Length(); i++ )
127 Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast( aProfiles.Value( i ) );
128 aMap.Bind( aProfile->GetTopShape(), aProfile->GetName() );
134 HYDROGUI_PolylineExtractionOp::ShapeMap HYDROGUI_PolylineExtractionOp::extract( const Handle(HYDROData_Channel)& aChannel )
137 if ( !aChannel.IsNull() )
139 HYDROData_SequenceOfObjects aGroups = aChannel->GetGroups();
140 int aNum = qMin( aGroups.Length(), 2 );
141 for ( int i = 1; i <= aNum; i++ )
143 Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast( aGroups.Value( i ) );
144 TopTools_SequenceOfShape aShapes;
145 aGroup->GetShapes( aShapes );
146 if ( !aShapes.IsEmpty() )
149 BRep_Builder aBuilder;
150 aBuilder.MakeWire( aWire );
152 for ( int s = 1; s <= aShapes.Length(); s++ )
153 aBuilder.Add( aWire, aShapes.Value( s ) );
154 aMap.Bind( aWire, i > 1 ? "Right bank" : "Left bank" );
161 HYDROGUI_PolylineExtractionOp::ShapeMap HYDROGUI_PolylineExtractionOp::extract( const Handle(HYDROData_Obstacle)& theObstacle )
164 if ( !theObstacle.IsNull() )
167 BRep_Builder aBuilder;
168 aBuilder.MakeWire( aWire );
169 HYDROData_SequenceOfObjects aGroups = theObstacle->GetGroups();
170 for ( int i = 1; i <= aGroups.Length(); i++ )
172 Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast( aGroups.Value( i ) );
173 TopTools_SequenceOfShape aShapes;
174 aGroup->GetShapes( aShapes );
175 for ( int s = 1; s <= aShapes.Length(); s++ )
176 aBuilder.Add( aWire, aShapes.Value( s ) );
178 aMap.Bind( aWire, "Contour" );