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 //TODO: 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();
87 double aTolerance = 1E-2; //TODO
89 HYDROData_PolylineOperator anOp;
90 switch( aPanel->GetMode() )
92 case HYDROGUI_SplitPolylinesDlg::ByPoint:
93 anOp.Split( doc(), aMainPolyline, aPoint, aTolerance );
95 case HYDROGUI_SplitPolylinesDlg::ByTool:
96 anOp.Split( doc(), aMainPolyline, aToolPolyline, aTolerance );
98 case HYDROGUI_SplitPolylinesDlg::Split:
99 anOp.Split( doc(), aPolylinesList, aTolerance );
103 theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer;
107 void HYDROGUI_SplitPolylinesOp::abortOperation()
110 HYDROGUI_Operation::abortOperation();
113 void HYDROGUI_SplitPolylinesOp::commitOperation()
116 HYDROGUI_Operation::commitOperation();
119 void HYDROGUI_SplitPolylinesOp::erasePreview()
128 void HYDROGUI_SplitPolylinesOp::OnUpdatePreview()
130 OCCViewer_ViewManager* aViewManager = getPreviewManager();
133 if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() )
135 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
136 if ( !aCtx.IsNull() )
139 myPreviewPrs = new HYDROGUI_Shape( aCtx, NULL, getPreviewZLayer() );
140 aCtx->ClearSelected();
145 HYDROGUI_SplitPolylinesDlg* aPanel = ::qobject_cast<HYDROGUI_SplitPolylinesDlg*>( inputPanel() );
146 if( myPreviewPrs && aPanel )
149 TopoDS_Compound aCmp;
150 aBB.MakeCompound( aCmp );
152 switch( aPanel->GetMode() )
154 case HYDROGUI_SplitPolylinesDlg::ByPoint:
156 gp_Pnt2d aPnt = aPanel->GetPoint();
157 TopoDS_Vertex aVertex = BRepLib_MakeVertex( gp_Pnt( aPnt.X(), aPnt.Y(), 0.0 ) );
158 if( !aPanel->GetMainPolyline().IsNull() )
159 aBB.Add( aCmp, aPanel->GetMainPolyline()->GetShape() );
160 aBB.Add( aCmp, aVertex );
163 case HYDROGUI_SplitPolylinesDlg::ByTool:
165 if( !aPanel->GetMainPolyline().IsNull() )
166 aBB.Add( aCmp, aPanel->GetMainPolyline()->GetShape() );
167 if( !aPanel->GetToolPolyline().IsNull() )
168 aBB.Add( aCmp, aPanel->GetToolPolyline()->GetShape() );
171 case HYDROGUI_SplitPolylinesDlg::Split:
173 HYDROData_SequenceOfObjects aPolylines = aPanel->GetPolylines();
174 for( int i=aPolylines.Lower(), n=aPolylines.Upper(); i<=n; i++ )
176 Handle( HYDROData_PolylineXY ) aPolyline = Handle( HYDROData_PolylineXY )::DownCast( aPolylines.Value( i ) );
177 if( !aPolyline.IsNull() )
178 aBB.Add( aCmp, aPolyline->GetShape() );
185 myPreviewPrs->setShape( aCmp );