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_LandCoverMapOp.h"
21 #include "HYDROGUI_Module.h"
22 #include "HYDROGUI_OCCDisplayer.h"
23 #include "HYDROGUI_Operations.h"
24 #include "HYDROGUI_LandCoverMapDlg.h"
25 #include "HYDROGUI_Tool2.h"
26 #include "HYDROGUI_UpdateFlags.h"
27 #include "HYDROGUI_DataObject.h"
28 #include "HYDROGUI_ShapeLandCoverMap.h"
29 #include "HYDROGUI_OCCSelector.h"
31 #include <HYDROData_Iterator.h>
32 #include <HYDROData_StricklerTable.h>
33 #include <HYDROData_PolylineXY.h>
34 #include <HYDROData_Object.h>
36 #include <OCCViewer_ViewManager.h>
37 #include <OCCViewer_ViewModel.h>
38 #include <OCCViewer_ViewWindow.h>
39 #include <OCCViewer_ViewPort3d.h>
41 #include <OCCViewer_ViewManager.h>
43 #include <SalomeApp_Study.h>
44 #include <LightApp_Application.h>
45 #include <LightApp_SelectionMgr.h>
46 #include <LightApp_DataOwner.h>
47 #include <SUIT_ViewWindow.h>
48 #include <SUIT_DataObject.h>
51 #include <TopoDS_Face.hxx>
52 #include <TopTools_ListOfShape.hxx>
53 #include <TopTools_ListIteratorOfListOfShape.hxx>
54 #include <AIS_Shape.hxx>
56 #include <QApplication>
57 #include <QMouseEvent>
59 HYDROGUI_LandCoverMapOp::HYDROGUI_LandCoverMapOp( HYDROGUI_Module* theModule, const int theOperationId )
60 : HYDROGUI_Operation( theModule ),
61 myOperationId( theOperationId ),
63 myPolylineFacePreviewPrs( 0 )
65 switch( myOperationId )
67 case CreateLandCoverMapId:
68 setName( tr( "CREATE_LAND_COVER_MAP" ) );
71 setName( tr( "ADD_LAND_COVER" ) );
73 case RemoveLandCoverId:
74 setName( tr( "REMOVE_LAND_COVER" ) );
76 case SplitLandCoverId:
77 setName( tr( "SPLIT_LAND_COVER" ) );
79 case MergeLandCoverId:
80 setName( tr( "MERGE_LAND_COVER" ) );
82 case ChangeLandCoverTypeId:
83 setName( tr( "CHANGE_LAND_COVER_TYPE" ) );
88 HYDROGUI_LandCoverMapOp::~HYDROGUI_LandCoverMapOp()
93 void HYDROGUI_LandCoverMapOp::startOperation()
95 HYDROGUI_Operation::startOperation();
97 HYDROGUI_LandCoverMapDlg* aPanel = ::qobject_cast<HYDROGUI_LandCoverMapDlg*>( inputPanel() );
101 aPanel->blockSignals( true );
105 // Set name of the created/edited land cover map object
106 QString anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_LAND_COVER_MAP_NAME" ) );
107 if ( myOperationId != CreateLandCoverMapId )
109 if ( isApplyAndClose() )
110 myEditedObject = Handle(HYDROData_LandCoverMap)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
112 // Construct a list of names of all land cover map objects defined within the data model
113 QStringList aLandCoverMapNames;
114 HYDROData_Iterator anIterator( doc(), KIND_LAND_COVER_MAP );
115 for( ; anIterator.More(); anIterator.Next() )
117 Handle(HYDROData_LandCoverMap) aLandCoverObj =
118 Handle(HYDROData_LandCoverMap)::DownCast( anIterator.Current() );
119 if ( !aLandCoverObj.IsNull() )
120 aLandCoverMapNames.append( aLandCoverObj->GetName() );
123 //aLandCoverMapNames.sort();
124 aPanel->setObjectNames( aLandCoverMapNames );
126 if ( myEditedObject.IsNull() )
128 if ( !aLandCoverMapNames.empty() )
130 anObjectName = aLandCoverMapNames.first();
131 if ( !anObjectName.isEmpty())
133 Handle(HYDROData_LandCoverMap) anObject =
134 Handle(HYDROData_LandCoverMap)::DownCast( HYDROGUI_Tool::FindObjectByName( module(), anObjectName ) );
135 if( !anObject.IsNull() )
136 myEditedObject = anObject;
141 anObjectName = myEditedObject->GetName();
143 aPanel->setObjectName( anObjectName );
146 if ( myOperationId != CreateLandCoverMapId )
149 aPanel->blockSignals( false );
151 module()->update( UF_OCCViewer | UF_FitAll );
154 void HYDROGUI_LandCoverMapOp::abortOperation()
158 bool aNoActiveOps = module()->getActiveOperations().isEmpty();
160 HYDROGUI_Operation::abortOperation();
162 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( module()->getApp()->activeStudy() );
163 if ( aStudy && !aNoActiveOps )
164 module()->update( UF_OCCViewer | UF_FitAll );
167 void HYDROGUI_LandCoverMapOp::commitOperation()
171 HYDROGUI_Operation::commitOperation();
173 module()->update( UF_OCCViewer | UF_FitAll );
176 HYDROGUI_InputPanel* HYDROGUI_LandCoverMapOp::createInputPanel() const
178 HYDROGUI_LandCoverMapDlg* aPanel = new HYDROGUI_LandCoverMapDlg( module(), getName(), myOperationId );
179 connect( aPanel, SIGNAL( landCoverMapChanged( const QString& ) ),
180 this, SLOT( onLandCoverMapChanged( const QString& ) ) );
181 connect( aPanel, SIGNAL( polylineFaceChanged() ),
182 this, SLOT( onPolylineFaceChanged() ) );
186 bool HYDROGUI_LandCoverMapOp::processApply( int& theUpdateFlags,
187 QString& theErrorMsg,
188 QStringList& theBrowseObjectsEntries )
190 HYDROGUI_LandCoverMapDlg* aPanel = ::qobject_cast<HYDROGUI_LandCoverMapDlg*>( inputPanel() );
194 // Check name of the created/edited object
195 QString anObjectName = aPanel->getObjectName().simplified();
196 if ( anObjectName.isEmpty() )
198 theErrorMsg = tr( "INCORRECT_OBJECT_NAME" );
202 if ( myOperationId == CreateLandCoverMapId || ( !myEditedObject.IsNull() && myEditedObject->GetName() != anObjectName ) )
204 // check that there are no other objects with the same name in the document
205 Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), anObjectName );
206 if( !anObject.IsNull() )
208 theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( anObjectName );
213 Handle(HYDROData_PolylineXY) aPolyline;
214 Handle(HYDROData_Object) aFace;
216 TopTools_ListOfShape aFacesSelectedInViewer;
218 // Get polyline/face selected in combo-box
219 if ( myOperationId == CreateLandCoverMapId || myOperationId == AddLandCoverId || myOperationId == SplitLandCoverId )
221 Handle(HYDROData_Entity) aPolylineFace = aPanel->getPolylineFace();
222 aPolyline = Handle(HYDROData_PolylineXY)::DownCast( aPolylineFace );
223 aFace = Handle(HYDROData_Object)::DownCast( aPolylineFace );
224 if ( aPolyline.IsNull() && aFace.IsNull() )
226 theErrorMsg = tr( "POLYLINE_FACE_NOT_DEFINED" );
230 // Get face(s) selected in the 3d viewer
231 else if ( myOperationId == RemoveLandCoverId ||
232 myOperationId == MergeLandCoverId ||
233 myOperationId == ChangeLandCoverTypeId )
236 // Fill in aFacesSelectedInViewer list
237 getSelectedShapes( aFacesSelectedInViewer );
240 // Get selected Strickler type
241 QString aSelectedStricklerType;
242 if ( myOperationId == CreateLandCoverMapId ||
243 myOperationId == AddLandCoverId ||
244 myOperationId == MergeLandCoverId ||
245 myOperationId == ChangeLandCoverTypeId )
247 aSelectedStricklerType = aPanel->getSelectedStricklerTypeName();
248 if ( aSelectedStricklerType.isEmpty() )
250 theErrorMsg = tr( "STRICKLER_TYPE_NOT_DEFINED" );
255 // Create / find the new / edited land cover map object
256 Handle(HYDROData_LandCoverMap) aLandCoverMapObj = myOperationId != CreateLandCoverMapId ? myEditedObject :
257 Handle(HYDROData_LandCoverMap)::DownCast( doc()->CreateObject( KIND_LAND_COVER_MAP ) );
258 if ( aLandCoverMapObj.IsNull() )
260 theErrorMsg = tr( "LAND_COVER_MAP_UNDEFINED" );
264 // Set land cover map name
265 aLandCoverMapObj->SetName( anObjectName );
267 // Add land cover to new / edited land cover map
268 if ( myOperationId == CreateLandCoverMapId || myOperationId == AddLandCoverId )
270 bool aLandCoverAdded = false;
271 if ( !aPolyline.IsNull() )
272 aLandCoverAdded = aLandCoverMapObj->Add( aPolyline, aSelectedStricklerType );
273 else if ( !aFace.IsNull() )
274 aLandCoverAdded = aLandCoverMapObj->Add( aFace, aSelectedStricklerType );
275 if ( !aLandCoverAdded )
277 theErrorMsg = tr( "LAND_COVER_NOT_ADDED" );
282 // Remove land cover from edited land cover map
283 if ( myOperationId == RemoveLandCoverId )
285 bool aLandCoverRemoved = false;
286 if ( !aFacesSelectedInViewer.IsEmpty() )
288 aLandCoverRemoved = aLandCoverMapObj->Remove( aFacesSelectedInViewer );
289 if ( !aLandCoverRemoved )
291 theErrorMsg = tr( "LAND_COVER_NOT_REMOVED" );
297 // Split land cover(s) inside edited land cover map
298 if ( myOperationId == SplitLandCoverId )
300 bool aLandCoverSplit = false;
301 if ( !aPolyline.IsNull() )
302 aLandCoverSplit = aLandCoverMapObj->Split( aPolyline );
303 else if ( !aFace.IsNull() )
305 // Get the complete boundary of the object face as the splitting polyline
306 QList<TopoDS_Shape> aBoundShapes;
307 QStringList aBoundNames;
308 aFace->GetBoundaries( aBoundShapes, aBoundNames );
310 for( int i=0, n=aBoundShapes.size(); i<n; i++ )
312 TopoDS_Shape aShape = aBoundShapes[i];
313 if( aShape.IsNull() )
316 bool aSplitResult = aLandCoverMapObj->Split( aShape );
317 aLandCoverSplit = ( i==0 ? aSplitResult : aLandCoverSplit && aSplitResult );
320 if ( !aLandCoverSplit )
322 theErrorMsg = tr( "LAND_COVER_NOT_SPLIT" );
327 // Merge land covers inside edited land cover map
328 if ( myOperationId == MergeLandCoverId )
330 bool aLandCoverMerged = false;
331 if ( !aFacesSelectedInViewer.IsEmpty() )
333 aLandCoverMerged = aLandCoverMapObj->Merge( aFacesSelectedInViewer, aSelectedStricklerType );
334 if ( !aLandCoverMerged )
336 theErrorMsg = tr( "LAND_COVER_NOT_MERGED" );
342 // Change Strickler type for land cover(s) inside edited land cover map
343 if ( myOperationId == ChangeLandCoverTypeId )
345 bool aLandCoverChangeType = false;
346 if ( !aFacesSelectedInViewer.IsEmpty() )
348 aLandCoverChangeType = aLandCoverMapObj->ChangeType( aFacesSelectedInViewer, aSelectedStricklerType );
349 if ( !aLandCoverChangeType )
351 theErrorMsg = tr( "LAND_COVER_TYPE_NOT_CHANGED" );
357 // Update land cover map object and close preview
358 aLandCoverMapObj->Update();
362 // Publish the newly created land cover map in the Object Browser
363 module()->setObjectVisible( HYDROGUI_Tool::GetActiveOCCViewId( module() ), aLandCoverMapObj, true );
364 if ( myOperationId == CreateLandCoverMapId )
366 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( aLandCoverMapObj );
367 theBrowseObjectsEntries.append( anEntry );
370 // Update presentation of land cover object in the 3d viewer
371 module()->setIsToUpdate( aLandCoverMapObj );
372 module()->getOCCDisplayer()->SetToUpdateColorScale();
374 theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer;
376 if ( myOperationId == CreateLandCoverMapId )
377 module()->enableLCMActions();
379 if ( myOperationId == RemoveLandCoverId || myOperationId == MergeLandCoverId || myOperationId == ChangeLandCoverTypeId )
380 aPanel->updateSelectedLandCoversLabel( getNbSelected() );
385 void HYDROGUI_LandCoverMapOp::onLandCoverMapChanged( const QString& theName )
387 // If the edited land cover map was changed in the combo-box, update myEditedObject
388 if ( myOperationId != CreateLandCoverMapId )
390 myEditedObject = Handle(HYDROData_LandCoverMap)::DownCast( HYDROGUI_Tool::FindObjectByName( module(), theName ) );
391 if ( !myEditedObject.IsNull() )
393 // Show preview of the newly selected land cover map
400 void HYDROGUI_LandCoverMapOp::onPolylineFaceChanged()
402 HYDROGUI_LandCoverMapDlg* aPanel = ::qobject_cast<HYDROGUI_LandCoverMapDlg*>( inputPanel() );
406 LightApp_DataOwner* aPolylineFaceDataOwner = NULL;
407 Handle(HYDROData_Entity) aPolylineFace = aPanel->getPolylineFace();
408 if ( !aPolylineFace.IsNull() )
410 // Select chosen polyline/face in the Object Browser, if it is not selected yet
411 // (i.e. object was chosen not in the Object Browser or 3d Viewer, but in combo-box)
412 aPolylineFaceDataOwner = new LightApp_DataOwner( HYDROGUI_DataObject::dataObjectEntry( aPolylineFace ) );
413 LightApp_SelectionMgr* aSelectionMgr = module()->getApp()->selectionMgr();
416 bool bIsAlreadySelected = false;
417 SUIT_DataOwnerPtrList aSelectedOwners;
418 aSelectionMgr->selected( aSelectedOwners );
419 foreach( SUIT_DataOwner* aSUITOwner, aSelectedOwners )
421 if ( LightApp_DataOwner* anOwner = dynamic_cast<LightApp_DataOwner*>( aSUITOwner ) )
423 if ( anOwner->entry() == aPolylineFaceDataOwner->entry() )
425 bIsAlreadySelected = true;
430 if ( !bIsAlreadySelected )
432 SUIT_DataOwnerPtrList aList( true );
433 aList.append( SUIT_DataOwnerPtr( aPolylineFaceDataOwner ) );
434 aSelectionMgr->setSelected( aList );
438 // Show Preview of selected polyline/face
439 Handle(HYDROData_PolylineXY) aPolyline = Handle(HYDROData_PolylineXY)::DownCast( aPolylineFace );
440 Handle(HYDROData_Object) aFace = Handle(HYDROData_Object)::DownCast( aPolylineFace );
441 if ( !aPolyline.IsNull() || !aFace.IsNull() )
443 TopoDS_Shape aTopoDSShape;
444 if ( !aPolyline.IsNull() )
445 aTopoDSShape = aPolyline->GetShape();
447 aTopoDSShape = aFace->GetTopShape();
449 OCCViewer_ViewManager* aViewManager = ::qobject_cast<OCCViewer_ViewManager*>(
450 module()->getApp()->getViewManager( OCCViewer_Viewer::Type(), true ) );
453 if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() )
455 if ( myPolylineFacePreviewPrs )
457 delete myPolylineFacePreviewPrs;
458 myPolylineFacePreviewPrs = 0;
461 int aViewerId = (size_t)aViewer;
462 if ( !module()->isObjectVisible( aViewerId, aPolylineFace ) )
464 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
465 if ( !aCtx.IsNull() )
467 myPolylineFacePreviewPrs = new HYDROGUI_Shape( aCtx, NULL, getPreviewZLayer() );
468 aCtx->ClearSelected();
470 myPolylineFacePreviewPrs->setBorderColor( Qt::white, false, false );
471 myPolylineFacePreviewPrs->setShape( aTopoDSShape, true, true, !aPolyline.IsNull() ? AIS_WireFrame : AIS_Shaded );
473 module()->update( UF_OCCViewer | UF_FitAll );
482 void HYDROGUI_LandCoverMapOp::onCreatePreview()
484 HYDROGUI_LandCoverMapDlg* aPanel = ::qobject_cast<HYDROGUI_LandCoverMapDlg*>( inputPanel() );
488 QApplication::setOverrideCursor( Qt::WaitCursor );
490 LightApp_Application* anApp = module()->getApp();
491 if ( !getPreviewManager() )
492 setPreviewManager( ::qobject_cast<OCCViewer_ViewManager*>(
493 anApp->getViewManager( OCCViewer_Viewer::Type(), true ) ) );
494 OCCViewer_ViewManager* aViewManager = getPreviewManager();
495 if ( aViewManager && !myPreviewPrs )
497 if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() )
499 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
500 if ( !aCtx.IsNull() )
502 if ( myOperationId == RemoveLandCoverId ||
503 myOperationId == MergeLandCoverId ||
504 myOperationId == ChangeLandCoverTypeId )
506 disconnect(aViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)),
507 aViewer, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
508 disconnect(aViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)),
509 aViewer, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
511 connect(aViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)),
512 this, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
513 connect(aViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)),
514 this, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
516 LightApp_SelectionMgr* aSelectionMgr = module()->getApp()->selectionMgr();
519 QList<SUIT_Selector*> aSelectorList;
520 aSelectionMgr->selectors( aViewManager->getType(), aSelectorList );
521 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
522 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
524 HYDROGUI_OCCSelector* aHydroSelector = dynamic_cast<HYDROGUI_OCCSelector*>( *anIter );
525 if ( aHydroSelector )
527 disconnect( aHydroSelector->viewer(), SIGNAL( deselection() ), aHydroSelector, SLOT( onDeselection() ) );
528 connect( this, SIGNAL( deselection() ), aHydroSelector, SLOT( onDeselection() ) );
533 connect( this, SIGNAL( selectionChanged() ), this, SLOT( onViewerSelectionChanged() ) );
536 connect( aViewer, SIGNAL( selectionChanged() ), this, SLOT( onViewerSelectionChanged() ) );
537 myPreviewPrs = new HYDROGUI_ShapeLandCoverMap( module()->getOCCDisplayer(), aCtx, myEditedObject, getPreviewZLayer()/*, theIsScalarMapMode*/ );
542 if ( aViewManager && myPreviewPrs && !myEditedObject.IsNull() )
544 if ( myOperationId == RemoveLandCoverId ||
545 myOperationId == MergeLandCoverId ||
546 myOperationId == ChangeLandCoverTypeId )
547 myPreviewPrs->setSelectionMode( AIS_Shape::SelectionMode( TopAbs_FACE ) );
548 myPreviewPrs->update( false, false );
550 if ( myOperationId == ChangeLandCoverTypeId )
551 selectLandCoverInPreview();
554 module()->update( UF_OCCViewer | UF_FitAll );
556 QApplication::restoreOverrideCursor();
559 void HYDROGUI_LandCoverMapOp::onViewerSelectionChanged()
561 HYDROGUI_LandCoverMapDlg* aPanel = ::qobject_cast<HYDROGUI_LandCoverMapDlg*>( inputPanel() );
565 int aNbSelected = getNbSelected();
567 if ( myOperationId == RemoveLandCoverId || myOperationId == ChangeLandCoverTypeId )
568 // Enable Apply, Apply and Close buttons only if at least one face (land cover) is selected in the 3d viewer
569 aPanel->setApplyEnabled( aNbSelected > 0 );
570 else if ( myOperationId == MergeLandCoverId )
571 // Enable Apply, Apply and Close buttons only if at least two faces (land covers) are selected in the 3d viewer
572 aPanel->setApplyEnabled( aNbSelected > 1 );
574 if ( myOperationId == MergeLandCoverId || myOperationId == ChangeLandCoverTypeId )
576 if ( aNbSelected == 1 && !myEditedObject.IsNull() )
578 TopTools_ListOfShape aFacesSelectedInViewer;
579 getSelectedShapes( aFacesSelectedInViewer );
580 if ( aFacesSelectedInViewer.Extent() == 1 )
582 QString aType = myEditedObject->StricklerType( TopoDS::Face( aFacesSelectedInViewer.First() ) );
583 if ( !aType.isEmpty() )
584 aPanel->setSelectedStricklerTypeName( aType );
589 if ( myOperationId == RemoveLandCoverId || myOperationId == MergeLandCoverId || myOperationId == ChangeLandCoverTypeId )
590 aPanel->updateSelectedLandCoversLabel( aNbSelected );
593 void HYDROGUI_LandCoverMapOp::onMousePress(SUIT_ViewWindow* theWindow, QMouseEvent* theEvent)
595 myStartPnt.setX(theEvent->x()); myStartPnt.setY(theEvent->y());
598 void HYDROGUI_LandCoverMapOp::onMouseRelease(SUIT_ViewWindow* theWindow, QMouseEvent* theEvent)
600 if (theEvent->button() != Qt::LeftButton) return;
601 if (!theWindow->inherits("OCCViewer_ViewWindow")) return;
603 OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*) theWindow;
607 OCCViewer_ViewManager* aViewManager = getPreviewManager();
611 OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer();
615 Handle(AIS_InteractiveContext) aCtx = getInteractiveContext();
619 myEndPnt.setX(theEvent->x()); myEndPnt.setY(theEvent->y());
621 if (myStartPnt == myEndPnt)
623 if ( !aViewer->isPreselectionEnabled() ) {
624 Handle(V3d_View) aView3d = aView->getViewPort()->getView();
625 if ( !aView3d.IsNull() ) {
626 aCtx->MoveTo(myEndPnt.x(), myEndPnt.y(), aView3d);
630 Handle(StdSelect_ViewerSelector3d) aMainSelector = aCtx->MainSelector();
631 if ( aMainSelector.IsNull() )
633 const Standard_Integer aDetectedNb = aMainSelector->NbPicked();
634 if ( aDetectedNb == 0 )
636 aCtx->ClearSelected( false );
640 for (Standard_Integer aDetIter = 1; aDetIter <= aDetectedNb; ++aDetIter)
642 Handle(SelectMgr_EntityOwner) anOwner = aMainSelector->Picked (aDetIter);
643 aCtx->AddOrRemoveSelected( anOwner, Standard_False );
648 aCtx->ShiftSelect(myStartPnt.x(), myStartPnt.y(),
649 myEndPnt.x(), myEndPnt.y(),
650 aView->getViewPort()->getView(), Standard_False );
653 aCtx->UpdateCurrentViewer();
654 emit selectionChanged();
657 void HYDROGUI_LandCoverMapOp::closePreview()
665 if ( myPolylineFacePreviewPrs )
667 delete myPolylineFacePreviewPrs;
668 myPolylineFacePreviewPrs = 0;
671 HYDROGUI_LandCoverMapDlg* aPanel = ::qobject_cast<HYDROGUI_LandCoverMapDlg*>( inputPanel() );
675 if ( myOperationId == RemoveLandCoverId || myOperationId == MergeLandCoverId || myOperationId == ChangeLandCoverTypeId )
676 aPanel->setApplyEnabled( false );
678 if ( myOperationId == RemoveLandCoverId ||
679 myOperationId == MergeLandCoverId ||
680 myOperationId == ChangeLandCoverTypeId )
682 OCCViewer_ViewManager* aViewManager = getPreviewManager();
685 if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() )
687 disconnect(aViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)),
688 this, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
689 disconnect(aViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)),
690 this, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
691 connect(aViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)),
692 aViewer, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
693 connect(aViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)),
694 aViewer, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
696 LightApp_SelectionMgr* aSelectionMgr = module()->getApp()->selectionMgr();
699 QList<SUIT_Selector*> aSelectorList;
700 aSelectionMgr->selectors( aViewManager->getType(), aSelectorList );
701 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
702 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
704 HYDROGUI_OCCSelector* aHydroSelector = dynamic_cast<HYDROGUI_OCCSelector*>( *anIter );
705 if ( aHydroSelector )
707 disconnect( this, SIGNAL( deselection() ), aHydroSelector, SLOT( onDeselection() ) );
708 connect( aHydroSelector->viewer(), SIGNAL( deselection() ), aHydroSelector, SLOT( onDeselection() ) );
717 Handle(AIS_InteractiveContext) HYDROGUI_LandCoverMapOp::getInteractiveContext()
719 OCCViewer_ViewManager* aViewManager = getPreviewManager();
720 Handle(AIS_InteractiveContext) aCtx = NULL;
721 if ( aViewManager ) {
722 if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() ) {
723 aCtx = aViewer->getAISContext();
729 void HYDROGUI_LandCoverMapOp::getSelectedShapes( TopTools_ListOfShape& theSelectedShapes )
731 Handle(AIS_InteractiveContext) aCtx = getInteractiveContext();
732 if ( !aCtx.IsNull() )
734 for ( aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected() )
736 TopoDS_Shape aSelectedShape = aCtx->SelectedShape();
737 if ( aSelectedShape.IsNull() )
740 theSelectedShapes.Append( aSelectedShape );
745 int HYDROGUI_LandCoverMapOp::getNbSelected()
749 Handle(AIS_InteractiveContext) aCtx = getInteractiveContext();
750 if ( !aCtx.IsNull() )
752 for ( aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected() )
754 TopoDS_Shape aSelectedShape = aCtx->SelectedShape();
755 if ( aSelectedShape.IsNull() )
764 void HYDROGUI_LandCoverMapOp::selectLandCoverInPreview()
766 if ( myPreviewPrs && !myEditedObject.IsNull() && myEditedObject->GetLCCount() == 1 )
768 OCCViewer_ViewManager* aViewManager = getPreviewManager();
772 Handle(AIS_InteractiveContext) aCtx = getInteractiveContext();
776 OCCViewer_ViewWindow* aViewWindow = (OCCViewer_ViewWindow*)aViewManager->getActiveView();
780 OCCViewer_ViewPort3d* aViewPort = aViewWindow->getViewPort();
784 Handle(V3d_View) aView = aViewPort->getView();
785 if ( aView.IsNull() )
788 aCtx->ShiftSelect( 0, 0, aViewPort->width(), aViewPort->height(), aView, Standard_False );
789 aCtx->UpdateCurrentViewer();
790 emit selectionChanged();