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();
380 void HYDROGUI_LandCoverMapOp::onLandCoverMapChanged( const QString& theName )
382 // If the edited land cover map was changed in the combo-box, update myEditedObject
383 if ( myOperationId != CreateLandCoverMapId )
385 myEditedObject = Handle(HYDROData_LandCoverMap)::DownCast( HYDROGUI_Tool::FindObjectByName( module(), theName ) );
386 if ( !myEditedObject.IsNull() )
388 // Show preview of the newly selected land cover map
395 void HYDROGUI_LandCoverMapOp::onPolylineFaceChanged()
397 HYDROGUI_LandCoverMapDlg* aPanel = ::qobject_cast<HYDROGUI_LandCoverMapDlg*>( inputPanel() );
401 LightApp_DataOwner* aPolylineFaceDataOwner = NULL;
402 Handle(HYDROData_Entity) aPolylineFace = aPanel->getPolylineFace();
403 if ( !aPolylineFace.IsNull() )
405 // Select chosen polyline/face in the Object Browser, if it is not selected yet
406 // (i.e. object was chosen not in the Object Browser or 3d Viewer, but in combo-box)
407 aPolylineFaceDataOwner = new LightApp_DataOwner( HYDROGUI_DataObject::dataObjectEntry( aPolylineFace ) );
408 LightApp_SelectionMgr* aSelectionMgr = module()->getApp()->selectionMgr();
411 bool bIsAlreadySelected = false;
412 SUIT_DataOwnerPtrList aSelectedOwners;
413 aSelectionMgr->selected( aSelectedOwners );
414 foreach( SUIT_DataOwner* aSUITOwner, aSelectedOwners )
416 if ( LightApp_DataOwner* anOwner = dynamic_cast<LightApp_DataOwner*>( aSUITOwner ) )
418 if ( anOwner->entry() == aPolylineFaceDataOwner->entry() )
420 bIsAlreadySelected = true;
425 if ( !bIsAlreadySelected )
427 SUIT_DataOwnerPtrList aList( true );
428 aList.append( SUIT_DataOwnerPtr( aPolylineFaceDataOwner ) );
429 aSelectionMgr->setSelected( aList );
433 // Show Preview of selected polyline/face
434 Handle(HYDROData_PolylineXY) aPolyline = Handle(HYDROData_PolylineXY)::DownCast( aPolylineFace );
435 Handle(HYDROData_Object) aFace = Handle(HYDROData_Object)::DownCast( aPolylineFace );
436 if ( !aPolyline.IsNull() || !aFace.IsNull() )
438 TopoDS_Shape aTopoDSShape;
439 if ( !aPolyline.IsNull() )
440 aTopoDSShape = aPolyline->GetShape();
442 aTopoDSShape = aFace->GetTopShape();
444 OCCViewer_ViewManager* aViewManager = ::qobject_cast<OCCViewer_ViewManager*>(
445 module()->getApp()->getViewManager( OCCViewer_Viewer::Type(), true ) );
448 if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() )
450 if ( myPolylineFacePreviewPrs )
452 delete myPolylineFacePreviewPrs;
453 myPolylineFacePreviewPrs = 0;
456 int aViewerId = (size_t)aViewer;
457 if ( !module()->isObjectVisible( aViewerId, aPolylineFace ) )
459 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
460 if ( !aCtx.IsNull() )
462 myPolylineFacePreviewPrs = new HYDROGUI_Shape( aCtx, NULL, getPreviewZLayer() );
463 aCtx->ClearSelected();
465 myPolylineFacePreviewPrs->setBorderColor( Qt::white, false, false );
466 myPolylineFacePreviewPrs->setShape( aTopoDSShape, true, true, !aPolyline.IsNull() ? AIS_WireFrame : AIS_Shaded );
468 module()->update( UF_OCCViewer | UF_FitAll );
477 void HYDROGUI_LandCoverMapOp::onCreatePreview()
479 HYDROGUI_LandCoverMapDlg* aPanel = ::qobject_cast<HYDROGUI_LandCoverMapDlg*>( inputPanel() );
483 QApplication::setOverrideCursor( Qt::WaitCursor );
485 LightApp_Application* anApp = module()->getApp();
486 if ( !getPreviewManager() )
487 setPreviewManager( ::qobject_cast<OCCViewer_ViewManager*>(
488 anApp->getViewManager( OCCViewer_Viewer::Type(), true ) ) );
489 OCCViewer_ViewManager* aViewManager = getPreviewManager();
490 if ( aViewManager && !myPreviewPrs )
492 if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() )
494 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
495 if ( !aCtx.IsNull() )
497 if ( myOperationId == RemoveLandCoverId ||
498 myOperationId == MergeLandCoverId ||
499 myOperationId == ChangeLandCoverTypeId )
501 disconnect(aViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)),
502 aViewer, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
503 disconnect(aViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)),
504 aViewer, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
506 connect(aViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)),
507 this, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
508 connect(aViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)),
509 this, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
511 LightApp_SelectionMgr* aSelectionMgr = module()->getApp()->selectionMgr();
514 QList<SUIT_Selector*> aSelectorList;
515 aSelectionMgr->selectors( aViewManager->getType(), aSelectorList );
516 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
517 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
519 HYDROGUI_OCCSelector* aHydroSelector = dynamic_cast<HYDROGUI_OCCSelector*>( *anIter );
520 if ( aHydroSelector )
522 disconnect( aHydroSelector->viewer(), SIGNAL( deselection() ), aHydroSelector, SLOT( onDeselection() ) );
523 connect( this, SIGNAL( deselection() ), aHydroSelector, SLOT( onDeselection() ) );
528 connect( this, SIGNAL( selectionChanged() ), this, SLOT( onViewerSelectionChanged() ) );
531 connect( aViewer, SIGNAL( selectionChanged() ), this, SLOT( onViewerSelectionChanged() ) );
532 myPreviewPrs = new HYDROGUI_ShapeLandCoverMap( module()->getOCCDisplayer(), aCtx, myEditedObject, getPreviewZLayer()/*, theIsScalarMapMode*/ );
537 if ( aViewManager && myPreviewPrs && !myEditedObject.IsNull() )
539 if ( myOperationId == RemoveLandCoverId ||
540 myOperationId == MergeLandCoverId ||
541 myOperationId == ChangeLandCoverTypeId )
542 myPreviewPrs->setSelectionMode( AIS_Shape::SelectionMode( TopAbs_FACE ) );
543 myPreviewPrs->update( false, false );
545 if ( myOperationId == ChangeLandCoverTypeId )
546 selectLandCoverInPreview();
549 module()->update( UF_OCCViewer | UF_FitAll );
551 QApplication::restoreOverrideCursor();
554 void HYDROGUI_LandCoverMapOp::onViewerSelectionChanged()
556 HYDROGUI_LandCoverMapDlg* aPanel = ::qobject_cast<HYDROGUI_LandCoverMapDlg*>( inputPanel() );
560 int aNbSelected = getNbSelected();
562 if ( myOperationId == RemoveLandCoverId || myOperationId == ChangeLandCoverTypeId )
563 // Enable Apply, Apply and Close buttons only if at least one face (land cover) is selected in the 3d viewer
564 aPanel->setApplyEnabled( aNbSelected > 0 );
565 else if ( myOperationId == MergeLandCoverId )
566 // Enable Apply, Apply and Close buttons only if at least two faces (land covers) are selected in the 3d viewer
567 aPanel->setApplyEnabled( aNbSelected > 1 );
569 if ( myOperationId == MergeLandCoverId || myOperationId == ChangeLandCoverTypeId )
571 if ( aNbSelected == 1 && !myEditedObject.IsNull() )
573 TopTools_ListOfShape aFacesSelectedInViewer;
574 getSelectedShapes( aFacesSelectedInViewer );
575 if ( aFacesSelectedInViewer.Extent() == 1 )
577 QString aType = myEditedObject->StricklerType( TopoDS::Face( aFacesSelectedInViewer.First() ) );
578 if ( !aType.isEmpty() )
579 aPanel->setSelectedStricklerTypeName( aType );
584 if ( myOperationId == RemoveLandCoverId || myOperationId == MergeLandCoverId || myOperationId == ChangeLandCoverTypeId )
585 aPanel->updateSelectedLandCoversLabel( aNbSelected );
588 void HYDROGUI_LandCoverMapOp::onMousePress(SUIT_ViewWindow* theWindow, QMouseEvent* theEvent)
590 myStartPnt.setX(theEvent->x()); myStartPnt.setY(theEvent->y());
593 void HYDROGUI_LandCoverMapOp::onMouseRelease(SUIT_ViewWindow* theWindow, QMouseEvent* theEvent)
595 if (theEvent->button() != Qt::LeftButton) return;
596 if (!theWindow->inherits("OCCViewer_ViewWindow")) return;
598 OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*) theWindow;
602 OCCViewer_ViewManager* aViewManager = getPreviewManager();
606 OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer();
610 Handle(AIS_InteractiveContext) aCtx = getInteractiveContext();
614 myEndPnt.setX(theEvent->x()); myEndPnt.setY(theEvent->y());
616 if (myStartPnt == myEndPnt)
618 if ( !aViewer->isPreselectionEnabled() ) {
619 Handle(V3d_View) aView3d = aView->getViewPort()->getView();
620 if ( !aView3d.IsNull() ) {
621 aCtx->MoveTo(myEndPnt.x(), myEndPnt.y(), aView3d);
625 Handle(StdSelect_ViewerSelector3d) aMainSelector = aCtx->MainSelector();
626 if ( aMainSelector.IsNull() )
628 const Standard_Integer aDetectedNb = aMainSelector->NbPicked();
629 if ( aDetectedNb == 0 )
631 aCtx->ClearSelected( false );
635 for (Standard_Integer aDetIter = 1; aDetIter <= aDetectedNb; ++aDetIter)
637 Handle(SelectMgr_EntityOwner) anOwner = aMainSelector->Picked (aDetIter);
638 aCtx->AddOrRemoveSelected( anOwner, Standard_False );
643 aCtx->ShiftSelect(myStartPnt.x(), myStartPnt.y(),
644 myEndPnt.x(), myEndPnt.y(),
645 aView->getViewPort()->getView(), Standard_False );
648 aCtx->UpdateCurrentViewer();
649 emit selectionChanged();
652 void HYDROGUI_LandCoverMapOp::closePreview()
660 if ( myPolylineFacePreviewPrs )
662 delete myPolylineFacePreviewPrs;
663 myPolylineFacePreviewPrs = 0;
666 HYDROGUI_LandCoverMapDlg* aPanel = ::qobject_cast<HYDROGUI_LandCoverMapDlg*>( inputPanel() );
670 if ( myOperationId == RemoveLandCoverId || myOperationId == MergeLandCoverId || myOperationId == ChangeLandCoverTypeId )
671 aPanel->setApplyEnabled( false );
673 if ( myOperationId == RemoveLandCoverId ||
674 myOperationId == MergeLandCoverId ||
675 myOperationId == ChangeLandCoverTypeId )
677 OCCViewer_ViewManager* aViewManager = getPreviewManager();
680 if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() )
682 disconnect(aViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)),
683 this, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
684 disconnect(aViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)),
685 this, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
686 connect(aViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)),
687 aViewer, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
688 connect(aViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)),
689 aViewer, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
691 LightApp_SelectionMgr* aSelectionMgr = module()->getApp()->selectionMgr();
694 QList<SUIT_Selector*> aSelectorList;
695 aSelectionMgr->selectors( aViewManager->getType(), aSelectorList );
696 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
697 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
699 HYDROGUI_OCCSelector* aHydroSelector = dynamic_cast<HYDROGUI_OCCSelector*>( *anIter );
700 if ( aHydroSelector )
702 disconnect( this, SIGNAL( deselection() ), aHydroSelector, SLOT( onDeselection() ) );
703 connect( aHydroSelector->viewer(), SIGNAL( deselection() ), aHydroSelector, SLOT( onDeselection() ) );
712 Handle(AIS_InteractiveContext) HYDROGUI_LandCoverMapOp::getInteractiveContext()
714 OCCViewer_ViewManager* aViewManager = getPreviewManager();
715 Handle(AIS_InteractiveContext) aCtx = NULL;
716 if ( aViewManager ) {
717 if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() ) {
718 aCtx = aViewer->getAISContext();
724 void HYDROGUI_LandCoverMapOp::getSelectedShapes( TopTools_ListOfShape& theSelectedShapes )
726 Handle(AIS_InteractiveContext) aCtx = getInteractiveContext();
727 if ( !aCtx.IsNull() )
729 for ( aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected() )
731 TopoDS_Shape aSelectedShape = aCtx->SelectedShape();
732 if ( aSelectedShape.IsNull() )
735 theSelectedShapes.Append( aSelectedShape );
740 int HYDROGUI_LandCoverMapOp::getNbSelected()
744 Handle(AIS_InteractiveContext) aCtx = getInteractiveContext();
745 if ( !aCtx.IsNull() )
747 for ( aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected() )
749 TopoDS_Shape aSelectedShape = aCtx->SelectedShape();
750 if ( aSelectedShape.IsNull() )
759 void HYDROGUI_LandCoverMapOp::selectLandCoverInPreview()
761 if ( myPreviewPrs && !myEditedObject.IsNull() && myEditedObject->GetLCCount() == 1 )
763 OCCViewer_ViewManager* aViewManager = getPreviewManager();
767 Handle(AIS_InteractiveContext) aCtx = getInteractiveContext();
771 OCCViewer_ViewWindow* aViewWindow = (OCCViewer_ViewWindow*)aViewManager->getActiveView();
775 OCCViewer_ViewPort3d* aViewPort = aViewWindow->getViewPort();
779 Handle(V3d_View) aView = aViewPort->getView();
780 if ( aView.IsNull() )
783 aCtx->ShiftSelect( 0, 0, aViewPort->width(), aViewPort->height(), aView, Standard_False );
784 aCtx->UpdateCurrentViewer();
785 emit selectionChanged();