+ erasePreview();
+}
+
+/**
+ * Redirect the delete action to input panel
+ */
+void HYDROGUI_PolylineOp::deleteSelected()
+{
+ HYDROGUI_PolylineDlg* aPanel = (HYDROGUI_PolylineDlg*)inputPanel();
+ aPanel->deleteSelected();
+}
+
+/**
+ * Checks whether there are some to delete
+ */
+bool HYDROGUI_PolylineOp::deleteEnabled()
+{
+ HYDROGUI_PolylineDlg* aPanel = (HYDROGUI_PolylineDlg*)inputPanel();
+ return aPanel->deleteEnabled();
+}
+
+/**
+ * Set Z layer for the operation preview.
+ \param theLayer a layer position
+ */
+void HYDROGUI_PolylineOp::updatePreviewZLayer( int theLayer )
+{
+ HYDROGUI_Operation::updatePreviewZLayer( theLayer );
+
+ int aZLayer = getPreviewZLayer();
+ if ( aZLayer >= 0 )
+ {
+ if( getPreviewManager() )
+ {
+ if ( OCCViewer_Viewer* aViewer = getPreviewManager()->getOCCViewer() )
+ {
+ Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
+ if( !aCtx.IsNull() )
+ {
+ Handle(AIS_InteractiveObject) anObject = myCurve->getAISObject( true );
+ aCtx->SetZLayer( anObject, aZLayer );
+ }
+ }
+ }
+ }
+}
+
+void HYDROGUI_PolylineOp::startOperation()
+{
+ if( myIsEdit )
+ {
+ if ( isApplyAndClose() )
+ myEditedObject = Handle(HYDROData_PolylineXY)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
+ if ( !myEditedObject.IsNull() && !myEditedObject->IsEditable() )
+ {
+ // Polyline is imported from GEOM module an is not recognized as
+ // polyline or spline and exist only as shape presentation
+ SUIT_MessageBox::critical( module()->getApp()->desktop(),
+ tr( "POLYLINE_IS_UNEDITABLE_TLT" ),
+ tr( "POLYLINE_IS_UNEDITABLE_MSG" ) );
+ abort();
+ return;
+ }
+ }
+
+ if( myCurve )
+ delete myCurve;
+
+ myCurve = new CurveCreator_Curve( CurveCreator::Dim2d );
+
+ HYDROGUI_Operation::startOperation();
+
+ HYDROGUI_PolylineDlg* aPanel = (HYDROGUI_PolylineDlg*)inputPanel();
+ aPanel->reset();
+
+ LightApp_Application* anApp = module()->getApp();
+ OCCViewer_ViewManager* aViewManager =
+ dynamic_cast<OCCViewer_ViewManager*>( anApp->getViewManager( OCCViewer_Viewer::Type(), true ) );
+ aPanel->setOCCViewer( aViewManager ? aViewManager->getOCCViewer() : 0 );
+ setPreviewManager( aViewManager );
+
+ if ( isApplyAndClose() )
+ setCursor();
+
+ QString aPolylineName;
+ if( !myEditedObject.IsNull() )
+ {
+ NCollection_Sequence<TCollection_AsciiString> aSectNames;
+ NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
+ NCollection_Sequence<bool> aSectClosures;
+ myEditedObject->GetSections( aSectNames, aSectTypes, aSectClosures );
+
+ for ( int i = 1, n = aSectNames.Size(); i <= n; ++i )
+ {
+ QString aSectName = HYDROGUI_Tool::ToQString( aSectNames.Value( i ) );
+ HYDROData_PolylineXY::SectionType aSectType = aSectTypes.Value( i );
+ bool aSectClosure = aSectClosures.Value( i );
+
+ CurveCreator::SectionType aCurveType = CurveCreator::Polyline;
+ if( aSectType == HYDROData_PolylineXY::SECTION_SPLINE )
+ aCurveType = CurveCreator::Spline;
+
+ CurveCreator::Coordinates aCurveCoords;
+
+ HYDROData_PolylineXY::PointsList aSectPointsList = myEditedObject->GetPoints( i - 1 );
+ for ( int k = 1, aNbPoints = aSectPointsList.Size(); k <= aNbPoints; ++k )
+ {
+ const HYDROData_PolylineXY::Point& aSectPoint = aSectPointsList.Value( k );
+ aCurveCoords.push_back( aSectPoint.X() );
+ aCurveCoords.push_back( aSectPoint.Y() );
+ }
+
+ myCurve->addSectionInternal( aSectName.toStdString(), aCurveType, aSectClosure, aCurveCoords );
+ }
+
+ aPolylineName = myEditedObject->GetName();
+ }
+ else
+ {
+ aPolylineName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_POLYLINE_NAME" ) );
+ }
+
+ aPanel->setPolylineName( aPolylineName );
+ aPanel->setCurve( myCurve );
+
+ displayPreview();
+}
+
+void HYDROGUI_PolylineOp::abortOperation()
+{
+ restoreCursor();
+
+ HYDROGUI_PolylineDlg* aPanel = (HYDROGUI_PolylineDlg*)inputPanel();
+ if ( aPanel )
+ aPanel->setOCCViewer( 0 );
+ erasePreview();
+
+ HYDROGUI_Operation::abortOperation();
+}
+
+void HYDROGUI_PolylineOp::commitOperation()
+{
+ if ( isApplyAndClose() )
+ {
+ restoreCursor();
+
+ HYDROGUI_PolylineDlg* aPanel = (HYDROGUI_PolylineDlg*)inputPanel();
+ if ( aPanel )
+ aPanel->setOCCViewer( 0 );
+ }
+
+ erasePreview();
+
+ HYDROGUI_Operation::commitOperation();