1 // SALOME OCCViewer : build OCC Viewer into Salome desktop
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : OCCViewer_Viewer3d.cxx
25 // Author : Nicolas REJNERI
30 \class OCCViewer_Viewer3d OCCViewer_Viewer3d.h
31 \brief Open CASCADE Viewer 3D with viewport 3D and selection.
34 #include "OCCViewer_Viewer3d.h"
35 #include "OCCViewer_ViewFrame.h"
36 #include "OCCViewer_AISSelector.h"
38 #include "QAD_Config.h"
39 #include "QAD_Desktop.h"
40 #include "QAD_Settings.h"
41 #include "QAD_LeftFrame.h"
42 #include "OCCViewer_ViewPort3d.h"
43 #include "QAD_RightFrame.h"
44 #include "QAD_MessageBox.h"
45 #include "QAD_Application.h"
47 #include "SALOME_Selection.h"
48 #include "SALOME_InteractiveObject.hxx"
49 #include "SALOME_ListIteratorOfListIO.hxx"
51 #include "SALOME_AISShape.hxx"
52 #include "SALOME_AISObject.hxx"
54 #include "utilities.h"
56 // Open CASCADE Includes
57 #include <Geom_Axis2Placement.hxx>
58 #include <AIS_ListOfInteractive.hxx>
59 #include <AIS_ListIteratorOfListOfInteractive.hxx>
60 #include <SelectMgr_EntityOwner.hxx>
61 #include <TopTools_IndexedMapOfShape.hxx>
63 #include <TColStd_IndexedMapOfInteger.hxx>
64 #include <NCollection_DefineBaseCollection.hxx>
65 #include <NCollection_DefineDataMap.hxx>
69 DEFINE_BASECOLLECTION( OCCViewer_CollectionOfIndexedMapOfShapes, TopTools_IndexedMapOfShape )
70 DEFINE_DATAMAP( OCCViewer_MapOfIOIndexedMapOfShape, OCCViewer_CollectionOfIndexedMapOfShapes, Handle_SALOME_InteractiveObject, TopTools_IndexedMapOfShape)
72 DEFINE_BASECOLLECTION( OCCViewer_CollectionOfMapOfInteger, TColStd_MapOfInteger )
73 DEFINE_DATAMAP( OCCViewer_MapOfIOMapOfInteger, OCCViewer_CollectionOfMapOfInteger, Handle_SALOME_InteractiveObject, TColStd_MapOfInteger )
78 OCCViewer_Viewer3d::OCCViewer_Viewer3d(OCCViewer_ViewFrame* vf) :
82 if ( myV3dViewer.IsNull() )
83 createViewer3d(); /* create viewer */
85 QString BackgroundColorRed = QAD_CONFIG->getSetting("OCCViewer:BackgroundColorRed");
86 QString BackgroundColorGreen = QAD_CONFIG->getSetting("OCCViewer:BackgroundColorGreen");
87 QString BackgroundColorBlue = QAD_CONFIG->getSetting("OCCViewer:BackgroundColorBlue");
89 if( !BackgroundColorRed.isEmpty() && !BackgroundColorGreen.isEmpty() && !BackgroundColorBlue.isEmpty() )
90 myBackColor = QColor(BackgroundColorRed.toInt(),
91 BackgroundColorGreen.toInt(),
92 BackgroundColorBlue.toInt());
94 myBackColor = QColor(35, 136, 145);
97 myViewFrame->setViewPort ( new OCCViewer_ViewPort3d( myViewFrame, myV3dViewer ) );
98 myViewFrame->setViewer(this);
100 /* properties settings */
101 // if ( !myIcon.isNull() )
102 // myStudyFrame->setIcon( myIcon );
104 myViewFrame->setCursor( myCursor );
105 myViewFrame->setBackgroundColor( myBackColor );
107 if ( myAISContext.IsNull() ) {
108 /* create interactive manager */
109 myAISContext = new AIS_InteractiveContext ( myV3dViewer, myV3dCollector );
111 myAISContext->IsoOnPlane(true) ;
113 /* create trihedron */
114 Handle(Geom_Axis2Placement) anAxis=new Geom_Axis2Placement(gp::XOY());
115 myTrihedron=new AIS_Trihedron(anAxis);
116 myTrihedron->SetInfiniteState( Standard_True );
118 Quantity_Color Col(193/255., 205/255., 193/255., Quantity_TOC_RGB);
119 myTrihedron->SetColor( Col );
120 myTrihedron->SetArrowColor( Col.Name() );
123 QString Size = QAD_CONFIG->getSetting("Viewer:TrihedronSize");
124 if (!Size. isEmpty() ) dim = Size.toFloat(); //get size from preferences
126 myTrihedron->SetSize(dim);
128 myAISContext->Display(myTrihedron);
129 myAISContext->Deactivate(myTrihedron);
131 /* create selector */
132 myAISSelector = new OCCViewer_AISSelector ( myAISContext );
133 QAD_ASSERT ( connect (myAISSelector, SIGNAL(selSelectionDone(bool)),
134 this, SLOT(onSelectionDone(bool))) );
135 QAD_ASSERT ( connect (myAISSelector, SIGNAL(selSelectionCancel(bool)),
136 this, SLOT(onSelectionCancel(bool))) );
137 myEnableSelection = true;
140 QAD_ASSERT ( connect(myViewFrame,
141 SIGNAL(vfKeyPress(QKeyEvent*)),
142 this, SLOT(onKeyPress(QKeyEvent*))) );
144 /* mouse events of the view */
145 QAD_ASSERT ( QObject::connect(myViewFrame,
146 SIGNAL(vfMousePress(QMouseEvent*)),
147 this, SLOT(onMousePress(QMouseEvent*))) );
148 QAD_ASSERT ( QObject::connect(myViewFrame,
149 SIGNAL(vfMouseRelease(QMouseEvent*)),
150 this, SLOT(onMouseRelease (QMouseEvent*))) );
151 QAD_ASSERT ( QObject::connect(myViewFrame,
152 SIGNAL(vfMouseMove(QMouseEvent*)),
153 this, SLOT(onMouseMove (QMouseEvent*))) );
154 QAD_ASSERT ( QObject::connect(myViewFrame,
155 SIGNAL(vfMouseDoubleClick(QMouseEvent*)),
156 this, SLOT(onMouseDoubleClick (QMouseEvent*))) );
158 /* transformation events */
159 QAD_ASSERT ( QObject::connect(myViewFrame,
160 SIGNAL(vfTransformationStarted(OCCViewer_ViewPort::OperationType)),
161 this, SLOT(onTransformationStarted (OCCViewer_ViewPort::OperationType))) );
162 QAD_ASSERT ( QObject::connect(myViewFrame,
163 SIGNAL(vfTransformationFinished(OCCViewer_ViewPort::OperationType)),
164 this, SLOT(onTransformationFinished (OCCViewer_ViewPort::OperationType))) );
166 /* set popup manager for the viewport */
167 myViewFrame->getViewPort()->setPopupServer ( this );
175 OCCViewer_Viewer3d::~OCCViewer_Viewer3d()
177 delete myAISSelector;
182 Handle(AIS_Trihedron) OCCViewer_Viewer3d::getTrihedron() const
187 void OCCViewer_Viewer3d::setTrihedronSize( float size )
189 AIS_ListOfInteractive aList;
190 myAISContext->DisplayedObjects( aList );
191 myAISContext->ObjectsInCollector( aList );
193 AIS_ListIteratorOfListOfInteractive anIter( aList );
194 for ( ; anIter.More(); anIter.Next() )
196 Handle(AIS_Trihedron) aTrh = Handle(AIS_Trihedron)::DownCast( anIter.Value() );
197 if ( !aTrh.IsNull() )
198 aTrh->SetSize( aTrh == myTrihedron ? size : 0.5 *size );
201 myAISContext->UpdateCurrentViewer();
204 bool OCCViewer_Viewer3d::isTrihedronDisplayed()
207 return myAISContext->IsDisplayed(myTrihedron);
210 void OCCViewer_Viewer3d::rename( const Handle(SALOME_InteractiveObject)& IObject, QString newName )
212 AIS_ListOfInteractive List;
213 myAISContext->DisplayedObjects(List);
215 AIS_ListIteratorOfListOfInteractive ite(List);
218 if (ite.Value()->IsKind(STANDARD_TYPE(SALOME_AISShape)))
220 Handle(SALOME_AISShape) aSh = Handle(SALOME_AISShape)::DownCast(ite.Value());
224 Handle(SALOME_InteractiveObject) IO = aSh->getIO();
225 if ( IO->isSame( IObject ) )
227 char* aCopyName = CORBA::string_dup(newName.latin1());
228 aSh->setName( aCopyName );
234 else if ( ite.Value()->IsKind( STANDARD_TYPE( SALOME_AISObject ) ) )
236 Handle(SALOME_AISObject) aSh = Handle(SALOME_AISObject)::DownCast( ite.Value() );
238 // Add code here, if someone create a MODULE_AISObject.
244 void OCCViewer_Viewer3d::SetColor(const Handle(SALOME_InteractiveObject)& IObject,
247 AIS_ListOfInteractive List;
248 myAISContext->DisplayedObjects(List);
250 AIS_ListIteratorOfListOfInteractive ite(List);
251 for ( ; ite.More(); ite.Next() )
253 Handle(SALOME_InteractiveObject) anObj =
254 Handle(SALOME_InteractiveObject)::DownCast( ite.Value()->GetOwner() );
256 if ( !anObj.IsNull() && anObj->hasEntry() && anObj->isSame( IObject ) )
258 Quantity_Color CSFColor = Quantity_Color ( thecolor.red() / 255.,
259 thecolor.green() / 255.,
260 thecolor.blue() / 255.,
262 ite.Value()->SetColor( CSFColor );
267 myV3dViewer->Update();
270 void OCCViewer_Viewer3d::SwitchRepresentation( const Handle(SALOME_InteractiveObject)& IObject,
273 AIS_ListOfInteractive List;
274 myAISContext->DisplayedObjects(List);
276 AIS_ListIteratorOfListOfInteractive ite(List);
277 for ( ; ite.More(); ite.Next() )
279 Handle(SALOME_InteractiveObject) anObj =
280 Handle(SALOME_InteractiveObject)::DownCast( ite.Value()->GetOwner() );
282 if ( !anObj.IsNull() && anObj->hasEntry() && anObj->isSame( IObject ) )
283 myAISContext->SetDisplayMode( ite.Value(), (Standard_Integer)mode ,true );
286 myV3dViewer->Update();
289 void OCCViewer_Viewer3d::SetTransparency( const Handle(SALOME_InteractiveObject)& IObject,
292 AIS_ListOfInteractive List;
293 myAISContext->DisplayedObjects( List );
295 AIS_ListIteratorOfListOfInteractive ite( List );
296 for ( ; ite.More(); ite.Next() )
298 Handle(SALOME_InteractiveObject) anObj =
299 Handle(SALOME_InteractiveObject)::DownCast( ite.Value()->GetOwner() );
301 if ( !anObj.IsNull() && anObj->hasEntry() && anObj->isSame( IObject ) )
303 myAISContext->SetTransparency( ite.Value(), transp, false );
304 myAISContext->Redisplay( ite.Value(), Standard_False, Standard_True );
308 myV3dViewer->Update();
312 Highlights 'obj' in viewer, returns 'true' when selected successfully
314 bool OCCViewer_Viewer3d::highlight( const Handle(SALOME_InteractiveObject)& IObject, bool highlight, bool update )
316 bool isInLocal = myAISContext->HasOpenedContext();
317 QAD_Study* ActiveStudy = QAD_Application::getDesktop()->getActiveStudy();
318 SALOME_Selection* Sel = SALOME_Selection::Selection( ActiveStudy->getSelection() );
320 AIS_ListOfInteractive List;
321 myAISContext->DisplayedObjects(List);
323 AIS_ListIteratorOfListOfInteractive ite(List);
324 for ( ; ite.More(); ite.Next() )
326 Handle(SALOME_InteractiveObject) anObj =
327 Handle(SALOME_InteractiveObject)::DownCast( ite.Value()->GetOwner() );
329 if ( !anObj.IsNull() && anObj->hasEntry() && anObj->isSame( IObject ) )
333 if ( highlight && !myAISContext->IsSelected( ite.Value() ) )
334 myAISContext->AddOrRemoveCurrentObject( ite.Value(), false );
335 else if ( !highlight && myAISContext->IsSelected( ite.Value() ) )
336 myAISContext->AddOrRemoveCurrentObject( ite.Value(), false );
338 // highlight subshapes only when local selection is active
341 if ( ite.Value()->IsKind( STANDARD_TYPE( SALOME_AISShape ) ) )
343 Handle(SALOME_AISShape) aSh = Handle(SALOME_AISShape)::DownCast( ite.Value() );
344 TColStd_IndexedMapOfInteger MapIndex;
345 Sel->GetIndex( IObject, MapIndex );
346 aSh->highlightSubShapes( MapIndex, highlight );
354 myV3dViewer->Redraw();
360 Unhighlight all selected objects
362 bool OCCViewer_Viewer3d::unHighlightAll()
364 if ( myAISContext->HasOpenedContext() )
365 myAISContext->ClearSelected();
367 myAISContext->ClearCurrents();
372 Returns true if the IObject has a Graphical Object in this viewer. Returns FALSE otherwise.
374 bool OCCViewer_Viewer3d::isInViewer( const Handle(SALOME_InteractiveObject)& IObject, bool onlyInViewer)
376 AIS_ListOfInteractive List;
377 myAISContext->DisplayedObjects(List);
379 if ( onlyInViewer ) {
380 AIS_ListOfInteractive List1;
381 myAISContext->ObjectsInCollector(List1);
385 AIS_ListIteratorOfListOfInteractive ite(List);
386 for ( ; ite.More(); ite.Next() )
388 Handle(SALOME_InteractiveObject) anObj =
389 Handle(SALOME_InteractiveObject)::DownCast( ite.Value()->GetOwner() );
391 if ( !anObj.IsNull() && anObj->hasEntry() && anObj->isSame( IObject ) )
397 bool OCCViewer_Viewer3d::isVisible( const Handle(SALOME_InteractiveObject)& IObject )
399 AIS_ListOfInteractive List;
400 myAISContext->DisplayedObjects( List );
402 AIS_ListIteratorOfListOfInteractive ite( List );
403 for ( ; ite.More(); ite.Next() )
405 Handle(SALOME_InteractiveObject) anObj =
406 Handle(SALOME_InteractiveObject)::DownCast( ite.Value()->GetOwner() );
408 if ( !anObj.IsNull() && anObj->hasEntry() && anObj->isSame( IObject ) )
409 return myAISContext->IsDisplayed( ite.Value() );
416 Returns the interactive context
418 Handle (AIS_InteractiveContext) OCCViewer_Viewer3d::getAISContext() const
423 OCCViewer_AISSelector* OCCViewer_Viewer3d::getAISSelector() const
425 return myAISSelector;
429 Returns 'true' if selection is enabled in this viewer,
432 bool OCCViewer_Viewer3d::enabledSelection() const
434 return myEnableSelection;
438 Enables/disables selection in the viewer
440 void OCCViewer_Viewer3d::enableSelection( bool enable )
442 myEnableSelection = enable;
443 myAISSelector->enableSelection( enable );
445 /* send notification */
446 emit vw3dSelectionEnabled( enable );
450 Enables/disables ordinary and multiple selection
451 ( by 'Shift' key or with a rectangle ) in this viewer.
453 void OCCViewer_Viewer3d::enableMultipleSelection( bool enable )
455 /* Enable/disable rectangle skectching which
456 is used for multiple selection */
457 myAISSelector->enableMultipleSelection( enable );
459 myViewFrame->getViewPort()->enableDrawMode( enable );
461 /* Enable non-multiple selection as well */
462 if ( !myEnableSelection && enable )
463 enableSelection( enable );
469 void OCCViewer_Viewer3d::onKeyPress( QKeyEvent* pe )
471 if (!QAD_Application::getDesktop()->getActiveComponent().isEmpty()) {
472 QAD_Application::getDesktop()->onKeyPress( pe );
479 void OCCViewer_Viewer3d::onMousePress( QMouseEvent* pe )
481 if ( pe->button() == Qt::LeftButton ) {
482 if ( !QAD_Application::getDesktop()->onMousePress( pe ) ) {
484 QAD_ASSERT_DEBUG_ONLY ( myAISSelector );
485 if ( pe->state() & Qt::ShiftButton )
486 myAISSelector->shiftSelect(); /* append selection */
488 myAISSelector->select(); /* new selection */
496 void OCCViewer_Viewer3d::onMouseMove( QMouseEvent* pe )
498 /* activate hilighting only if no MB pressed */
499 if ( ! ( pe->state() & ( Qt::LeftButton | Qt::MidButton | Qt::RightButton ) ) ) {
500 QAD_Application::getDesktop()->onMouseMove( pe );
501 OCCViewer_ViewPort* vp = myViewFrame->getViewPort();
502 myAISSelector->moveTo ( pe->x(), pe->y(), ((OCCViewer_ViewPort3d*)vp)->getView() );
509 void OCCViewer_Viewer3d::onMouseRelease( QMouseEvent* pe )
511 /* Selection with a rectangle ( multiple ) */
512 OCCViewer_ViewPort* vp = myViewFrame->getViewPort();
513 QAD_ASSERT_DEBUG_ONLY ( vp );
514 QRect selRect = vp->getSelectionRect ();
515 if ( selRect.isValid() ) {
516 QAD_ASSERT_DEBUG_ONLY ( myAISSelector );
517 QAD_ASSERT_DEBUG_ONLY ( vp->inherits("OCCViewer_ViewPort3d") );
518 if ( pe->state() & Qt::ShiftButton )
519 myAISSelector->shiftSelect ( selRect.left(), selRect.top(),
520 selRect.right(), selRect.bottom(),
521 ((OCCViewer_ViewPort3d*)vp)->getView() );
523 myAISSelector->select ( selRect.left(), selRect.top(),
524 selRect.right(), selRect.bottom(),
525 ((OCCViewer_ViewPort3d*)vp)->getView() );
532 void OCCViewer_Viewer3d::onMouseDoubleClick( QMouseEvent* pe )
537 Called when a transformation in viewport is started
539 void OCCViewer_Viewer3d::onTransformationStarted( OCCViewer_ViewPort::OperationType type )
541 QAD_ASSERT_DEBUG_ONLY ( myAISSelector );
542 if ( myEnableSelection )
543 myAISSelector->enableSelection ( false ); // lock until the end of transform
545 if ( type == OCCViewer_ViewPort::PANGLOBAL ||
546 type == OCCViewer_ViewPort::WINDOWFIT )
548 /* Start watching 'global panning' and 'window fit'.
549 These operations require additional user's actions
550 in viewport and we have to reset the operations if
551 instead of these actions a user does something else.
553 qApp->installEventFilter( this );
558 Called when a transformation in viewport is finished
560 void OCCViewer_Viewer3d::onTransformationFinished( OCCViewer_ViewPort::OperationType type )
562 QAD_ASSERT_DEBUG_ONLY ( myAISSelector );
563 if ( myEnableSelection )
564 myAISSelector->enableSelection ( true ); // unlock
566 if ( type == OCCViewer_ViewPort::PANGLOBAL ||
567 type == OCCViewer_ViewPort::WINDOWFIT )
569 /* stop watching 'global panning' and 'window fit'*/
570 qApp->removeEventFilter( this );
575 Called when an object is selected
577 void OCCViewer_Viewer3d::onSelectionDone( bool bAdded )
579 emit vw3dSelectionDone( bAdded );
581 // QAD_Study* myActiveStudy = QAD_Application::getDesktop()->getActiveStudy();
582 // QAD_StudyFrame* myActiveSFrame = myActiveStudy->getActiveStudyFrame();
583 // SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
584 // MESSAGE ( "OCCViewer_Viewer3d - NB SELECTED INTERACTIVE OBJECT : " << Sel->IObjectCount() )
586 QString ActiveComp = QAD_Application::getDesktop()->getActiveComponent();
588 if ( ActiveComp.isEmpty() )
594 if ( myAISContext->IndexOfCurrentLocal() <= 0 )
595 globalSelectionDone( bAdded );
597 localSelectionDone( bAdded );
599 myV3dViewer->Update();
603 Called when an object is selected and there is no opened local context
605 void OCCViewer_Viewer3d::globalSelectionDone( const bool bAdded )
607 SALOME_Selection* Sel = SALOME_Selection::Selection(
608 QAD_Application::getDesktop()->getActiveStudy()->getSelection() );
610 MESSAGE ( "OCCViewer_Viewer3d - NB SELECTED INTERACTIVE OBJECT : " << Sel->IObjectCount() )
612 SALOME_ListIO DeltaPos;
614 SALOME_ListIO DeltaNeg;
619 for ( myAISContext->InitCurrent(); myAISContext->MoreCurrent(); myAISContext->NextCurrent() )
621 Handle(SALOME_InteractiveObject) anObj =
622 Handle(SALOME_InteractiveObject)::DownCast( myAISContext->Current()->GetOwner() );
624 if ( !anObj.IsNull() )
626 bool itemAllreadySelected = false;
627 int nbSel = Sel->IObjectCount();
629 DeltaPos.Append( anObj );
632 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
633 for( ; It.More(); It.Next() )
635 Handle( SALOME_InteractiveObject) IO1 = It.Value();
636 if ( anObj->isSame( IO1 ) )
638 itemAllreadySelected = true;
642 if ( !itemAllreadySelected )
643 DeltaPos.Append( anObj );
646 else if ( myAISContext->Current()->IsKind( STANDARD_TYPE( SALOME_AISObject ) ) )
648 //Handle(SALOME_AISObject) aSh =
649 // Handle(SALOME_AISObject)::DownCast( myAISContext->Current() );
650 // Add code here, if someone create a MODULE_AISObject.
654 if ( DeltaPos.Extent() > 0 )
655 Sel->ClearIObjects();
660 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
661 for ( ;It.More(); It.Next() )
663 Handle( SALOME_InteractiveObject) IO1 = It.Value();
665 bool itemAllreadySelected = false;
666 for ( myAISContext->InitCurrent(); myAISContext->MoreCurrent(); myAISContext->NextCurrent() )
668 Handle(SALOME_InteractiveObject) anObj =
669 Handle(SALOME_InteractiveObject)::DownCast( myAISContext->Current()->GetOwner() );
671 if ( !anObj.IsNull() && anObj->isSame( IO1 ) )
673 itemAllreadySelected = true;
676 else if ( myAISContext->Current()->IsKind( STANDARD_TYPE( SALOME_AISObject ) ) )
678 //Handle(SALOME_AISObject) aSh =
679 // Handle(SALOME_AISObject)::DownCast(myAISContext->Current());
680 // Add code here, if someone create a MODULE_AISObject.
684 if ( !itemAllreadySelected )
685 DeltaNeg.Append( IO1 );
688 myAISContext->InitCurrent();
689 for ( myAISContext->InitCurrent(); myAISContext->MoreCurrent(); myAISContext->NextCurrent() )
691 Handle(SALOME_InteractiveObject) anObj =
692 Handle(SALOME_InteractiveObject)::DownCast( myAISContext->Current()->GetOwner() );
694 if ( !anObj.IsNull() )
696 bool itemAllreadySelected = false;
697 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
698 for ( ;It.More(); It.Next() )
700 Handle( SALOME_InteractiveObject) IO1 = It.Value();
702 if ( anObj->isSame( IO1 ) )
704 itemAllreadySelected = true;
709 if ( !itemAllreadySelected )
710 DeltaPos.Append( anObj );
712 else if ( myAISContext->Current()->IsKind(STANDARD_TYPE(SALOME_AISObject)))
714 //Handle(SALOME_AISObject) aSh =
715 // Handle(SALOME_AISObject)::DownCast(myAISContext->Current());
716 // Add code here, if someone create a MODULE_AISObject.
721 // MESSAGE ( "VIEWER onSelectionDone DeltaNeg.count() == " << DeltaNeg.count() )
722 SALOME_ListIteratorOfListIO ItNeg( DeltaNeg );
723 for( ;ItNeg.More();ItNeg.Next() )
725 Sel->RemoveIObject( ItNeg.Value(), false );
728 // MESSAGE ( "VIEWER onSelectionDone DeltaPos.count() == " << DeltaPos.Extent() )
729 SALOME_ListIteratorOfListIO ItPos( DeltaPos );
730 for ( ;ItPos.More();ItPos.Next() )
732 Sel->AddIObject( ItPos.Value(), false );
737 Called when an object is selected and there is opened local context
739 void OCCViewer_Viewer3d::localSelectionDone( const bool /*bAdded*/ )
741 SALOME_Selection* aSelection = SALOME_Selection::Selection(
742 QAD_Application::getDesktop()->getActiveStudy()->getSelection() );
744 aSelection->BlockSignals( true );
746 OCCViewer_MapOfIOIndexedMapOfShape aMapsOfShapes; // SALOME_InteractiveObject <--> TopTools_IndexedMapOfShape
747 OCCViewer_MapOfIOMapOfInteger aMapsOfIndexes; // SALOME_InteractiveObject <--> TColStd_MapOfInteger
750 // Iterate through selected objects and add them to selection
751 for( myAISContext->InitSelected(); myAISContext->MoreSelected(); myAISContext->NextSelected() )
753 // Retrive selected shape and subshape
754 Handle(SelectMgr_EntityOwner) anOwner = myAISContext->SelectedOwner();
755 if ( anOwner.IsNull() )
758 Handle(AIS_InteractiveObject) anIO =
759 Handle(AIS_InteractiveObject)::DownCast( myAISContext->SelectedInteractive() );
763 Handle(SALOME_InteractiveObject) anObj =
764 Handle(SALOME_InteractiveObject)::DownCast( anIO->GetOwner() );
765 if ( anObj.IsNull() )
768 if ( anIO->IsKind( STANDARD_TYPE( AIS_Shape ) ) )
770 Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast( anIO );
771 TopoDS_Shape aShape = anAISShape->Shape();
772 TopoDS_Shape aSubShape = anOwner->Shape();
773 if ( aShape.IsNull() || aSubShape.IsNull() )
776 // Get index of selected shape
777 if ( aMapsOfShapes.IsBound( anObj ) )
779 const TopTools_IndexedMapOfShape& aShapes = aMapsOfShapes( anObj );
780 int anIndex = aShapes.FindIndex( aSubShape );
782 aMapsOfIndexes( anObj ).Add( anIndex );
786 TopTools_IndexedMapOfShape aShapes;
787 TopExp::MapShapes( aShape, aShapes );
788 int anIndex = aShapes.FindIndex( aSubShape );
790 TColStd_MapOfInteger anIndexes;
791 anIndexes.Add( anIndex );
793 aMapsOfShapes.Bind( anObj, aShapes );
794 aMapsOfIndexes.Bind( anObj, anIndexes );
799 aMapsOfShapes.Bind( anObj, TopTools_IndexedMapOfShape() );
800 aMapsOfIndexes.Bind( anObj, TColStd_MapOfInteger() );
805 aSelection->ClearIObjects();
807 // Add object in selection
808 OCCViewer_MapOfIOMapOfInteger::Iterator anIter( aMapsOfIndexes );
809 for ( ; anIter.More(); anIter.Next() )
811 if ( anIter.Value().IsEmpty() )
812 aSelection->AddIObject( anIter.Key(), false );
815 aSelection->AddIObject( anIter.Key(), false );
816 aSelection->AddOrRemoveIndex( anIter.Key(), anIter.Value(), false, false );
820 aSelection->BlockSignals( false );
821 aSelection->SelectionChanged();
825 Called when an object is unselected
827 void OCCViewer_Viewer3d::onSelectionCancel( bool bAdded )
829 emit vw3dSelectionCancel();
831 QAD_Study* myActiveStudy = QAD_Application::getDesktop()->getActiveStudy();
832 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
834 SALOME_ListIO DeltaPos;
836 SALOME_ListIO DeltaNeg;
841 Sel->ClearIObjects();
845 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
846 for ( ; It.More(); It.Next() )
848 Handle( SALOME_InteractiveObject) IO1 = It.Value();
850 bool itemAllreadySelected = false;
851 myAISContext->InitCurrent();
852 for ( myAISContext->InitCurrent(); myAISContext->MoreCurrent(); myAISContext->NextCurrent() )
854 Handle(SALOME_InteractiveObject) anObj =
855 Handle(SALOME_InteractiveObject)::DownCast( myAISContext->Current()->GetOwner() );
857 if ( !anObj.IsNull() && anObj->isSame( IO1 ) )
859 itemAllreadySelected = true;
862 else if ( myAISContext->Current()->IsKind( STANDARD_TYPE( SALOME_AISObject ) ) )
864 Handle(SALOME_AISObject) aSh =
865 Handle(SALOME_AISObject)::DownCast(myAISContext->Current());
866 // Add code here, if someone create a MODULE_AISObject.
871 if ( !itemAllreadySelected )
872 DeltaNeg.Append( IO1 );
876 // MESSAGE ( "VIEWER onSelectionCancel DeltaNeg.count() == " << DeltaNeg.Extent() )
877 SALOME_ListIteratorOfListIO ItNeg( DeltaNeg );
878 for ( ; ItNeg.More(); ItNeg.Next() )
879 Sel->RemoveIObject( ItNeg.Value(), false);
881 myV3dViewer->Update();
885 Installed while 'fit area' and 'global panning'
886 operations are active
888 bool OCCViewer_Viewer3d::eventFilter( QObject * po, QEvent * pe)
890 if ( ( pe->type() == QEvent::MouseButtonPress &&
891 po != myViewFrame->getViewPort() ) ||
892 pe->type() == QEvent::KeyPress ) {
893 /* user press any key or a MB outside the viewport */
894 myViewFrame->getViewPort()->resetState();
896 return QObject::eventFilter( po, pe );
900 Creates CasCade viewer 3D
902 void OCCViewer_Viewer3d::createViewer3d()
904 myV3dViewer = OCCViewer_VService::Viewer ( "", (short*) "Viewer3d", "", 1000.,
905 V3d_XposYnegZpos, true, true);
908 myV3dCollector = OCCViewer_VService::Viewer ( "", (short*) "Collector3d", "", 1000.,
909 V3d_XposYnegZpos, true, true);
910 myV3dCollector->Init();
914 Returns CasCade viewer 3D
916 Handle(V3d_Viewer) OCCViewer_Viewer3d::getViewer3d() const
922 Sets a new cursor on all its studyframes
924 void OCCViewer_Viewer3d::setCursor( const QCursor& cursor)
930 Returns the current cursor
932 inline const QCursor& OCCViewer_Viewer3d::cursor() const
938 Sets default background color on all its studyframes
940 void OCCViewer_Viewer3d::setBackgroundColor( const QColor& aColor )
942 myBackColor = aColor;
946 Returns the current background
948 inline const QColor& OCCViewer_Viewer3d::backgroundColor() const
954 Sets a new icon to all its studyframes
956 void OCCViewer_Viewer3d::setIcon( const QPixmap& icon )
964 inline const QPixmap& OCCViewer_Viewer3d::icon() const
972 void OCCViewer_Viewer3d::onCreatePopup()