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_SplitPolylinesOp.h>
20 #include <HYDROGUI_SplitPolylinesDlg.h>
21 #include <HYDROGUI_Module.h>
22 #include <HYDROGUI_UpdateFlags.h>
23 #include <HYDROGUI_Shape.h>
24 #include <HYDROData_PolylineOperator.h>
25 #include <HYDROData_Document.h>
26 #include <LightApp_Application.h>
27 #include <OCCViewer_ViewModel.h>
28 #include <OCCViewer_ViewManager.h>
29 #include <gp_Pnt2d.hxx>
30 #include <BRepLib_MakeVertex.hxx>
31 #include <BRep_Builder.hxx>
32 #include <TopoDS_Vertex.hxx>
33 #include <TopoDS_Compound.hxx>
35 HYDROGUI_SplitPolylinesOp::HYDROGUI_SplitPolylinesOp( HYDROGUI_Module* theModule )
36 : HYDROGUI_Operation( theModule ),
39 setName( tr( "SPLIT_POLYLINES" ) );
42 HYDROGUI_SplitPolylinesOp::~HYDROGUI_SplitPolylinesOp()
46 void HYDROGUI_SplitPolylinesOp::startOperation()
48 HYDROGUI_Operation::startOperation();
50 HYDROGUI_SplitPolylinesDlg* aPanel =
51 ::qobject_cast<HYDROGUI_SplitPolylinesDlg*>( inputPanel() );
55 aPanel->setPolylinesFromSelection();
56 LightApp_Application* anApp = module()->getApp();
57 OCCViewer_ViewManager* aViewManager =
58 dynamic_cast<OCCViewer_ViewManager*>( anApp->getViewManager( OCCViewer_Viewer::Type(), true ) );
59 aPanel->setOCCViewer( aViewManager ? aViewManager->getOCCViewer() : 0 );
60 setPreviewManager( aViewManager );
65 HYDROGUI_InputPanel* HYDROGUI_SplitPolylinesOp::createInputPanel() const
67 HYDROGUI_SplitPolylinesDlg* aDlg = new HYDROGUI_SplitPolylinesDlg( module(), getName() );
68 connect( aDlg, SIGNAL( pointMoved() ), this, SLOT( OnUpdatePreview() ) );
69 connect( aDlg, SIGNAL( modeChanged() ), this, SLOT( OnUpdatePreview() ) );
70 connect( aDlg, SIGNAL( selectionChanged() ), this, SLOT( OnUpdatePreview() ) );
74 bool HYDROGUI_SplitPolylinesOp::processApply( int& theUpdateFlags,
76 QStringList& theBrowseObjectsEntries )
78 HYDROGUI_SplitPolylinesDlg* aPanel = ::qobject_cast<HYDROGUI_SplitPolylinesDlg*>( inputPanel() );
82 QString aName = aPanel->GetResultName();
83 Handle( HYDROData_PolylineXY ) aMainPolyline = aPanel->GetMainPolyline();
84 Handle( HYDROData_PolylineXY ) aToolPolyline = aPanel->GetToolPolyline();
85 HYDROData_SequenceOfObjects aPolylinesList = aPanel->GetPolylines();
86 gp_Pnt2d aPoint = aPanel->GetPoint();
88 HYDROData_PolylineOperator anOp;
89 switch( aPanel->GetMode() )
91 case HYDROGUI_SplitPolylinesDlg::ByPoint:
92 anOp.Split( doc(), aName.toLatin1().data(), aMainPolyline, aPoint );
94 case HYDROGUI_SplitPolylinesDlg::ByTool:
95 anOp.Split( doc(), aName.toLatin1().data(), aMainPolyline, aToolPolyline );
97 case HYDROGUI_SplitPolylinesDlg::Split:
98 anOp.Split( doc(), aName.toLatin1().data(), aPolylinesList );
102 theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer;
106 void HYDROGUI_SplitPolylinesOp::abortOperation()
109 HYDROGUI_Operation::abortOperation();
112 void HYDROGUI_SplitPolylinesOp::commitOperation()
115 HYDROGUI_Operation::commitOperation();
118 void HYDROGUI_SplitPolylinesOp::erasePreview()
127 void HYDROGUI_SplitPolylinesOp::OnUpdatePreview()
129 OCCViewer_ViewManager* aViewManager = getPreviewManager();
132 if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() )
134 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
135 if ( !aCtx.IsNull() )
138 myPreviewPrs = new HYDROGUI_Shape( aCtx, NULL, getPreviewZLayer() );
139 aCtx->ClearSelected();
144 HYDROGUI_SplitPolylinesDlg* aPanel = ::qobject_cast<HYDROGUI_SplitPolylinesDlg*>( inputPanel() );
145 if( myPreviewPrs && aPanel )
148 TopoDS_Compound aCmp;
149 aBB.MakeCompound( aCmp );
151 switch( aPanel->GetMode() )
153 case HYDROGUI_SplitPolylinesDlg::ByPoint:
155 gp_Pnt2d aPnt = aPanel->GetPoint();
156 TopoDS_Vertex aVertex = BRepLib_MakeVertex( gp_Pnt( aPnt.X(), aPnt.Y(), 0.0 ) );
157 if( !aPanel->GetMainPolyline().IsNull() )
158 aBB.Add( aCmp, aPanel->GetMainPolyline()->GetShape() );
159 aBB.Add( aCmp, aVertex );
162 case HYDROGUI_SplitPolylinesDlg::ByTool:
164 if( !aPanel->GetMainPolyline().IsNull() )
165 aBB.Add( aCmp, aPanel->GetMainPolyline()->GetShape() );
166 if( !aPanel->GetToolPolyline().IsNull() )
167 aBB.Add( aCmp, aPanel->GetToolPolyline()->GetShape() );
170 case HYDROGUI_SplitPolylinesDlg::Split:
172 HYDROData_SequenceOfObjects aPolylines = aPanel->GetPolylines();
173 for( int i=aPolylines.Lower(), n=aPolylines.Upper(); i<=n; i++ )
175 Handle( HYDROData_PolylineXY ) aPolyline = Handle( HYDROData_PolylineXY )::DownCast( aPolylines.Value( i ) );
176 if( !aPolyline.IsNull() )
177 aBB.Add( aCmp, aPolyline->GetShape() );
184 myPreviewPrs->setShape( aCmp );