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 HYDROGUI_Operation::abortOperation();
160 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( module()->getApp()->activeStudy() );
162 module()->update( UF_OCCViewer | UF_FitAll );
165 void HYDROGUI_LandCoverMapOp::commitOperation()
169 HYDROGUI_Operation::commitOperation();
171 module()->update( UF_OCCViewer | UF_FitAll );
174 HYDROGUI_InputPanel* HYDROGUI_LandCoverMapOp::createInputPanel() const
176 HYDROGUI_LandCoverMapDlg* aPanel = new HYDROGUI_LandCoverMapDlg( module(), getName(), myOperationId );
177 connect( aPanel, SIGNAL( landCoverMapChanged( const QString& ) ),
178 this, SLOT( onLandCoverMapChanged( const QString& ) ) );
179 connect( aPanel, SIGNAL( polylineFaceChanged() ),
180 this, SLOT( onPolylineFaceChanged() ) );
184 bool HYDROGUI_LandCoverMapOp::processApply( int& theUpdateFlags,
185 QString& theErrorMsg,
186 QStringList& theBrowseObjectsEntries )
188 HYDROGUI_LandCoverMapDlg* aPanel = ::qobject_cast<HYDROGUI_LandCoverMapDlg*>( inputPanel() );
192 // Check name of the created/edited object
193 QString anObjectName = aPanel->getObjectName().simplified();
194 if ( anObjectName.isEmpty() )
196 theErrorMsg = tr( "INCORRECT_OBJECT_NAME" );
200 if ( myOperationId == CreateLandCoverMapId || ( !myEditedObject.IsNull() && myEditedObject->GetName() != anObjectName ) )
202 // check that there are no other objects with the same name in the document
203 Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), anObjectName );
204 if( !anObject.IsNull() )
206 theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( anObjectName );
211 Handle(HYDROData_PolylineXY) aPolyline;
212 Handle(HYDROData_Object) aFace;
214 TopTools_ListOfShape aFacesSelectedInViewer;
216 // Get polyline/face selected in combo-box
217 if ( myOperationId == CreateLandCoverMapId || myOperationId == AddLandCoverId || myOperationId == SplitLandCoverId )
219 Handle(HYDROData_Entity) aPolylineFace = aPanel->getPolylineFace();
220 aPolyline = Handle(HYDROData_PolylineXY)::DownCast( aPolylineFace );
221 aFace = Handle(HYDROData_Object)::DownCast( aPolylineFace );
222 if ( aPolyline.IsNull() && aFace.IsNull() )
224 theErrorMsg = tr( "POLYLINE_FACE_NOT_DEFINED" );
228 // Get face(s) selected in the 3d viewer
229 else if ( myOperationId == RemoveLandCoverId ||
230 myOperationId == MergeLandCoverId ||
231 myOperationId == ChangeLandCoverTypeId )
234 // Fill in aFacesSelectedInViewer list
235 getSelectedShapes( aFacesSelectedInViewer );
238 // Get selected Strickler type
239 QString aSelectedStricklerType;
240 if ( myOperationId == CreateLandCoverMapId ||
241 myOperationId == AddLandCoverId ||
242 myOperationId == MergeLandCoverId ||
243 myOperationId == ChangeLandCoverTypeId )
245 aSelectedStricklerType = aPanel->getSelectedStricklerTypeName();
246 if ( aSelectedStricklerType.isEmpty() )
248 theErrorMsg = tr( "STRICKLER_TYPE_NOT_DEFINED" );
253 // Create / find the new / edited land cover map object
254 Handle(HYDROData_LandCoverMap) aLandCoverMapObj = myOperationId != CreateLandCoverMapId ? myEditedObject :
255 Handle(HYDROData_LandCoverMap)::DownCast( doc()->CreateObject( KIND_LAND_COVER_MAP ) );
256 if ( aLandCoverMapObj.IsNull() )
258 theErrorMsg = tr( "LAND_COVER_MAP_UNDEFINED" );
262 // Set land cover map name
263 aLandCoverMapObj->SetName( anObjectName );
265 // Add land cover to new / edited land cover map
266 if ( myOperationId == CreateLandCoverMapId || myOperationId == AddLandCoverId )
268 bool aLandCoverAdded = false;
269 if ( !aPolyline.IsNull() )
270 aLandCoverAdded = aLandCoverMapObj->Add( aPolyline, aSelectedStricklerType );
271 else if ( !aFace.IsNull() )
272 aLandCoverAdded = aLandCoverMapObj->Add( aFace, aSelectedStricklerType );
273 if ( !aLandCoverAdded )
275 theErrorMsg = tr( "LAND_COVER_NOT_ADDED" );
280 // Remove land cover from edited land cover map
281 if ( myOperationId == RemoveLandCoverId )
283 bool aLandCoverRemoved = false;
284 if ( !aFacesSelectedInViewer.IsEmpty() )
286 aLandCoverRemoved = aLandCoverMapObj->Remove( aFacesSelectedInViewer );
287 if ( !aLandCoverRemoved )
289 theErrorMsg = tr( "LAND_COVER_NOT_REMOVED" );
295 // Split land cover(s) inside edited land cover map
296 if ( myOperationId == SplitLandCoverId )
298 bool aLandCoverSplit = false;
299 if ( !aPolyline.IsNull() )
300 aLandCoverSplit = aLandCoverMapObj->Split( aPolyline );
301 else if ( !aFace.IsNull() )
303 // Get the complete boundary of the object face as the splitting polyline
304 QList<TopoDS_Shape> aBoundShapes;
305 QStringList aBoundNames;
306 aFace->GetBoundaries( aBoundShapes, aBoundNames );
308 for( int i=0, n=aBoundShapes.size(); i<n; i++ )
310 TopoDS_Shape aShape = aBoundShapes[i];
311 if( aShape.IsNull() )
314 bool aSplitResult = aLandCoverMapObj->Split( aShape );
315 aLandCoverSplit = ( i==0 ? aSplitResult : aLandCoverSplit && aSplitResult );
318 if ( !aLandCoverSplit )
320 theErrorMsg = tr( "LAND_COVER_NOT_SPLIT" );
325 // Merge land covers inside edited land cover map
326 if ( myOperationId == MergeLandCoverId )
328 bool aLandCoverMerged = false;
329 if ( !aFacesSelectedInViewer.IsEmpty() )
331 aLandCoverMerged = aLandCoverMapObj->Merge( aFacesSelectedInViewer, aSelectedStricklerType );
332 if ( !aLandCoverMerged )
334 theErrorMsg = tr( "LAND_COVER_NOT_MERGED" );
340 // Change Strickler type for land cover(s) inside edited land cover map
341 if ( myOperationId == ChangeLandCoverTypeId )
343 bool aLandCoverChangeType = false;
344 if ( !aFacesSelectedInViewer.IsEmpty() )
346 aLandCoverChangeType = aLandCoverMapObj->ChangeType( aFacesSelectedInViewer, aSelectedStricklerType );
347 if ( !aLandCoverChangeType )
349 theErrorMsg = tr( "LAND_COVER_TYPE_NOT_CHANGED" );
355 // Update land cover map object and close preview
356 aLandCoverMapObj->Update();
360 // Publish the newly created land cover map in the Object Browser
361 module()->setObjectVisible( HYDROGUI_Tool::GetActiveOCCViewId( module() ), aLandCoverMapObj, true );
362 if ( myOperationId == CreateLandCoverMapId )
364 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( aLandCoverMapObj );
365 theBrowseObjectsEntries.append( anEntry );
368 // Update presentation of land cover object in the 3d viewer
369 module()->setIsToUpdate( aLandCoverMapObj );
370 module()->getOCCDisplayer()->SetToUpdateColorScale();
372 theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer;
374 if ( myOperationId == CreateLandCoverMapId )
375 module()->enableLCMActions();
377 if ( myOperationId == RemoveLandCoverId || myOperationId == MergeLandCoverId || myOperationId == ChangeLandCoverTypeId )
378 aPanel->updateSelectedLandCoversLabel( getNbSelected() );
383 void HYDROGUI_LandCoverMapOp::onLandCoverMapChanged( const QString& theName )
385 // If the edited land cover map was changed in the combo-box, update myEditedObject
386 if ( myOperationId != CreateLandCoverMapId )
388 myEditedObject = Handle(HYDROData_LandCoverMap)::DownCast( HYDROGUI_Tool::FindObjectByName( module(), theName ) );
389 if ( !myEditedObject.IsNull() )
391 // Show preview of the newly selected land cover map
398 void HYDROGUI_LandCoverMapOp::onPolylineFaceChanged()
400 HYDROGUI_LandCoverMapDlg* aPanel = ::qobject_cast<HYDROGUI_LandCoverMapDlg*>( inputPanel() );
404 LightApp_DataOwner* aPolylineFaceDataOwner = NULL;
405 Handle(HYDROData_Entity) aPolylineFace = aPanel->getPolylineFace();
406 if ( !aPolylineFace.IsNull() )
408 // Select chosen polyline/face in the Object Browser, if it is not selected yet
409 // (i.e. object was chosen not in the Object Browser or 3d Viewer, but in combo-box)
410 aPolylineFaceDataOwner = new LightApp_DataOwner( HYDROGUI_DataObject::dataObjectEntry( aPolylineFace ) );
411 LightApp_SelectionMgr* aSelectionMgr = module()->getApp()->selectionMgr();
414 bool bIsAlreadySelected = false;
415 SUIT_DataOwnerPtrList aSelectedOwners;
416 aSelectionMgr->selected( aSelectedOwners );
417 foreach( SUIT_DataOwner* aSUITOwner, aSelectedOwners )
419 if ( LightApp_DataOwner* anOwner = dynamic_cast<LightApp_DataOwner*>( aSUITOwner ) )
421 if ( anOwner->entry() == aPolylineFaceDataOwner->entry() )
423 bIsAlreadySelected = true;
428 if ( !bIsAlreadySelected )
430 SUIT_DataOwnerPtrList aList( true );
431 aList.append( SUIT_DataOwnerPtr( aPolylineFaceDataOwner ) );
432 aSelectionMgr->setSelected( aList );
436 // Show Preview of selected polyline/face
437 Handle(HYDROData_PolylineXY) aPolyline = Handle(HYDROData_PolylineXY)::DownCast( aPolylineFace );
438 Handle(HYDROData_Object) aFace = Handle(HYDROData_Object)::DownCast( aPolylineFace );
439 if ( !aPolyline.IsNull() || !aFace.IsNull() )
441 TopoDS_Shape aTopoDSShape;
442 if ( !aPolyline.IsNull() )
443 aTopoDSShape = aPolyline->GetShape();
445 aTopoDSShape = aFace->GetTopShape();
447 OCCViewer_ViewManager* aViewManager = ::qobject_cast<OCCViewer_ViewManager*>(
448 module()->getApp()->getViewManager( OCCViewer_Viewer::Type(), true ) );
451 if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() )
453 if ( myPolylineFacePreviewPrs )
455 delete myPolylineFacePreviewPrs;
456 myPolylineFacePreviewPrs = 0;
459 int aViewerId = (size_t)aViewer;
460 if ( !module()->isObjectVisible( aViewerId, aPolylineFace ) )
462 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
463 if ( !aCtx.IsNull() )
465 myPolylineFacePreviewPrs = new HYDROGUI_Shape( aCtx, NULL, getPreviewZLayer() );
466 aCtx->ClearSelected();
468 myPolylineFacePreviewPrs->setBorderColor( Qt::white, false, false );
469 myPolylineFacePreviewPrs->setShape( aTopoDSShape, true, true, !aPolyline.IsNull() ? AIS_WireFrame : AIS_Shaded );
471 module()->update( UF_OCCViewer | UF_FitAll );
480 void HYDROGUI_LandCoverMapOp::onCreatePreview()
482 HYDROGUI_LandCoverMapDlg* aPanel = ::qobject_cast<HYDROGUI_LandCoverMapDlg*>( inputPanel() );
486 QApplication::setOverrideCursor( Qt::WaitCursor );
488 LightApp_Application* anApp = module()->getApp();
489 if ( !getPreviewManager() )
490 setPreviewManager( ::qobject_cast<OCCViewer_ViewManager*>(
491 anApp->getViewManager( OCCViewer_Viewer::Type(), true ) ) );
492 OCCViewer_ViewManager* aViewManager = getPreviewManager();
493 if ( aViewManager && !myPreviewPrs )
495 if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() )
497 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
498 if ( !aCtx.IsNull() )
500 if ( myOperationId == RemoveLandCoverId ||
501 myOperationId == MergeLandCoverId ||
502 myOperationId == ChangeLandCoverTypeId )
504 disconnect(aViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)),
505 aViewer, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
506 disconnect(aViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)),
507 aViewer, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
509 connect(aViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)),
510 this, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
511 connect(aViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)),
512 this, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
514 LightApp_SelectionMgr* aSelectionMgr = module()->getApp()->selectionMgr();
517 QList<SUIT_Selector*> aSelectorList;
518 aSelectionMgr->selectors( aViewManager->getType(), aSelectorList );
519 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
520 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
522 HYDROGUI_OCCSelector* aHydroSelector = dynamic_cast<HYDROGUI_OCCSelector*>( *anIter );
523 if ( aHydroSelector )
525 disconnect( aHydroSelector->viewer(), SIGNAL( deselection() ), aHydroSelector, SLOT( onDeselection() ) );
526 connect( this, SIGNAL( deselection() ), aHydroSelector, SLOT( onDeselection() ) );
531 connect( this, SIGNAL( selectionChanged() ), this, SLOT( onViewerSelectionChanged() ) );
534 connect( aViewer, SIGNAL( selectionChanged() ), this, SLOT( onViewerSelectionChanged() ) );
535 myPreviewPrs = new HYDROGUI_ShapeLandCoverMap( module()->getOCCDisplayer(), aCtx, myEditedObject, getPreviewZLayer()/*, theIsScalarMapMode*/ );
540 if ( aViewManager && myPreviewPrs && !myEditedObject.IsNull() )
542 if ( myOperationId == RemoveLandCoverId ||
543 myOperationId == MergeLandCoverId ||
544 myOperationId == ChangeLandCoverTypeId )
545 myPreviewPrs->setSelectionMode( AIS_Shape::SelectionMode( TopAbs_FACE ) );
546 myPreviewPrs->update( false, false );
548 if ( myOperationId == ChangeLandCoverTypeId )
549 selectLandCoverInPreview();
552 module()->update( UF_OCCViewer | UF_FitAll );
554 QApplication::restoreOverrideCursor();
557 void HYDROGUI_LandCoverMapOp::onViewerSelectionChanged()
559 HYDROGUI_LandCoverMapDlg* aPanel = ::qobject_cast<HYDROGUI_LandCoverMapDlg*>( inputPanel() );
563 int aNbSelected = getNbSelected();
565 if ( myOperationId == RemoveLandCoverId || myOperationId == ChangeLandCoverTypeId )
566 // Enable Apply, Apply and Close buttons only if at least one face (land cover) is selected in the 3d viewer
567 aPanel->setApplyEnabled( aNbSelected > 0 );
568 else if ( myOperationId == MergeLandCoverId )
569 // Enable Apply, Apply and Close buttons only if at least two faces (land covers) are selected in the 3d viewer
570 aPanel->setApplyEnabled( aNbSelected > 1 );
572 if ( myOperationId == MergeLandCoverId || myOperationId == ChangeLandCoverTypeId )
574 if ( aNbSelected == 1 && !myEditedObject.IsNull() )
576 TopTools_ListOfShape aFacesSelectedInViewer;
577 getSelectedShapes( aFacesSelectedInViewer );
578 if ( aFacesSelectedInViewer.Extent() == 1 )
580 QString aType = myEditedObject->StricklerType( TopoDS::Face( aFacesSelectedInViewer.First() ) );
581 if ( !aType.isEmpty() )
582 aPanel->setSelectedStricklerTypeName( aType );
587 if ( myOperationId == RemoveLandCoverId || myOperationId == MergeLandCoverId || myOperationId == ChangeLandCoverTypeId )
588 aPanel->updateSelectedLandCoversLabel( aNbSelected );
591 void HYDROGUI_LandCoverMapOp::onMousePress(SUIT_ViewWindow* theWindow, QMouseEvent* theEvent)
593 myStartPnt.setX(theEvent->x()); myStartPnt.setY(theEvent->y());
596 void HYDROGUI_LandCoverMapOp::onMouseRelease(SUIT_ViewWindow* theWindow, QMouseEvent* theEvent)
598 if (theEvent->button() != Qt::LeftButton) return;
599 if (!theWindow->inherits("OCCViewer_ViewWindow")) return;
601 OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*) theWindow;
605 OCCViewer_ViewManager* aViewManager = getPreviewManager();
609 OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer();
613 Handle(AIS_InteractiveContext) aCtx = getInteractiveContext();
617 myEndPnt.setX(theEvent->x()); myEndPnt.setY(theEvent->y());
619 if (myStartPnt == myEndPnt)
621 if ( !aViewer->isPreselectionEnabled() ) {
622 Handle(V3d_View) aView3d = aView->getViewPort()->getView();
623 if ( !aView3d.IsNull() ) {
624 aCtx->MoveTo(myEndPnt.x(), myEndPnt.y(), aView3d);
628 Handle(StdSelect_ViewerSelector3d) aMainSelector = aCtx->MainSelector();
629 if ( aMainSelector.IsNull() )
631 const Standard_Integer aDetectedNb = aMainSelector->NbPicked();
632 if ( aDetectedNb == 0 )
634 aCtx->ClearSelected( false );
638 for (Standard_Integer aDetIter = 1; aDetIter <= aDetectedNb; ++aDetIter)
640 Handle(SelectMgr_EntityOwner) anOwner = aMainSelector->Picked (aDetIter);
641 aCtx->AddOrRemoveSelected( anOwner, Standard_False );
646 aCtx->ShiftSelect(myStartPnt.x(), myStartPnt.y(),
647 myEndPnt.x(), myEndPnt.y(),
648 aView->getViewPort()->getView(), Standard_False );
651 aCtx->UpdateCurrentViewer();
652 emit selectionChanged();
655 void HYDROGUI_LandCoverMapOp::closePreview()
663 if ( myPolylineFacePreviewPrs )
665 delete myPolylineFacePreviewPrs;
666 myPolylineFacePreviewPrs = 0;
669 HYDROGUI_LandCoverMapDlg* aPanel = ::qobject_cast<HYDROGUI_LandCoverMapDlg*>( inputPanel() );
673 if ( myOperationId == RemoveLandCoverId || myOperationId == MergeLandCoverId || myOperationId == ChangeLandCoverTypeId )
674 aPanel->setApplyEnabled( false );
676 if ( myOperationId == RemoveLandCoverId ||
677 myOperationId == MergeLandCoverId ||
678 myOperationId == ChangeLandCoverTypeId )
680 OCCViewer_ViewManager* aViewManager = getPreviewManager();
683 if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() )
685 disconnect(aViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)),
686 this, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
687 disconnect(aViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)),
688 this, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
689 connect(aViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)),
690 aViewer, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
691 connect(aViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)),
692 aViewer, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
694 LightApp_SelectionMgr* aSelectionMgr = module()->getApp()->selectionMgr();
697 QList<SUIT_Selector*> aSelectorList;
698 aSelectionMgr->selectors( aViewManager->getType(), aSelectorList );
699 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
700 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
702 HYDROGUI_OCCSelector* aHydroSelector = dynamic_cast<HYDROGUI_OCCSelector*>( *anIter );
703 if ( aHydroSelector )
705 disconnect( this, SIGNAL( deselection() ), aHydroSelector, SLOT( onDeselection() ) );
706 connect( aHydroSelector->viewer(), SIGNAL( deselection() ), aHydroSelector, SLOT( onDeselection() ) );
715 Handle(AIS_InteractiveContext) HYDROGUI_LandCoverMapOp::getInteractiveContext()
717 OCCViewer_ViewManager* aViewManager = getPreviewManager();
718 Handle(AIS_InteractiveContext) aCtx = NULL;
719 if ( aViewManager ) {
720 if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() ) {
721 aCtx = aViewer->getAISContext();
727 void HYDROGUI_LandCoverMapOp::getSelectedShapes( TopTools_ListOfShape& theSelectedShapes )
729 Handle(AIS_InteractiveContext) aCtx = getInteractiveContext();
730 if ( !aCtx.IsNull() )
732 for ( aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected() )
734 TopoDS_Shape aSelectedShape = aCtx->SelectedShape();
735 if ( aSelectedShape.IsNull() )
738 theSelectedShapes.Append( aSelectedShape );
743 int HYDROGUI_LandCoverMapOp::getNbSelected()
747 Handle(AIS_InteractiveContext) aCtx = getInteractiveContext();
748 if ( !aCtx.IsNull() )
750 for ( aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected() )
752 TopoDS_Shape aSelectedShape = aCtx->SelectedShape();
753 if ( aSelectedShape.IsNull() )
762 void HYDROGUI_LandCoverMapOp::selectLandCoverInPreview()
764 if ( myPreviewPrs && !myEditedObject.IsNull() && myEditedObject->GetLCCount() == 1 )
766 OCCViewer_ViewManager* aViewManager = getPreviewManager();
770 Handle(AIS_InteractiveContext) aCtx = getInteractiveContext();
774 OCCViewer_ViewWindow* aViewWindow = (OCCViewer_ViewWindow*)aViewManager->getActiveView();
778 OCCViewer_ViewPort3d* aViewPort = aViewWindow->getViewPort();
782 Handle(V3d_View) aView = aViewPort->getView();
783 if ( aView.IsNull() )
786 aCtx->ShiftSelect( 0, 0, aViewPort->width(), aViewPort->height(), aView, Standard_False );
787 aCtx->UpdateCurrentViewer();
788 emit selectionChanged();