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_ViewFrame.cxx
25 // Author : Nicolas REJNERI
29 #include "OCCViewer_ViewFrame.h"
30 #include "OCCViewer_Viewer3d.h"
31 #include "OCCViewer_ViewPort.h"
32 #include "OCCViewer_ViewPort3d.h"
33 #include "OCCViewer_Prs.h"
36 #include "QAD_Tools.h"
37 #include "QAD_Desktop.h"
38 #include "QAD_ViewFrame.h"
39 #include "QAD_MessageBox.h"
40 #include "QAD_Application.h"
41 #include "utilities.h"
43 #include "QAD_Config.h"
44 #include "QAD_Settings.h"
45 #include "SALOME_Selection.h"
46 #include "SALOME_AISShape.hxx"
49 #include <qapplication.h>
51 // Open CASCADE Include
52 #include <V3d_View.hxx>
53 #include <AIS_ListIteratorOfListOfInteractive.hxx>
54 #include <Visual3d_View.hxx>
60 OCCViewer_ViewFrame::OCCViewer_ViewFrame(QWidget* parent, const QString& title)
61 : QAD_ViewFrame (parent, "")
69 OCCViewer_ViewFrame::OCCViewer_ViewFrame( QWidget* parent )
70 : QAD_ViewFrame (parent, "")
78 OCCViewer_ViewFrame::~OCCViewer_ViewFrame()
86 void OCCViewer_ViewFrame::initialize()
89 myViewer = new OCCViewer_Viewer3d( this );
91 /* enable/disable selection */
92 myViewer->enableSelection( true );
93 myViewer->enableMultipleSelection( true );
99 void OCCViewer_ViewFrame::cleanup()
105 Sets the viewport for this frame
107 void OCCViewer_ViewFrame::setViewPort( OCCViewer_ViewPort* view )
111 setCentralWidget ( myViewPort );
115 Inits the viewport for this frame
117 void OCCViewer_ViewFrame::initViewPort()
119 /* Active Key Event */
122 /* Initial attributes */
123 myViewPort->setCursor( cursor() );
124 myViewPort->setBackgroundColor( backgroundColor() );
126 QAD_ASSERT ( QObject::connect(myViewPort, SIGNAL(vpKeyPress (QKeyEvent*)),
127 this, SIGNAL(vfKeyPress(QKeyEvent*))) );
129 /* Listen to my viewport */
130 QAD_ASSERT ( QObject::connect(myViewPort,
131 SIGNAL(vpTransformationStarted (OCCViewer_ViewPort::OperationType)),
133 SIGNAL(vfTransformationStarted(OCCViewer_ViewPort::OperationType))) );
134 QAD_ASSERT ( QObject::connect( myViewPort,
135 SIGNAL(vpTransformationFinished (OCCViewer_ViewPort::OperationType)),
137 SIGNAL(vfTransformationFinished(OCCViewer_ViewPort::OperationType))) );
139 QAD_ASSERT ( QObject::connect(myViewPort, SIGNAL(vpDrawExternal (QPainter*)),
140 this, SIGNAL(vfDrawExternal(QPainter*))) );
141 QAD_ASSERT ( QObject::connect(myViewPort, SIGNAL(vpMousePress (QMouseEvent*)),
142 this, SIGNAL(vfMousePress(QMouseEvent*))) );
143 QAD_ASSERT ( QObject::connect(myViewPort, SIGNAL(vpMouseRelease (QMouseEvent*)),
144 this, SIGNAL(vfMouseRelease(QMouseEvent*))) );
145 QAD_ASSERT ( QObject::connect(myViewPort, SIGNAL(vpMouseMove (QMouseEvent*)),
146 this, SIGNAL(vfMouseMove(QMouseEvent*))) );
147 QAD_ASSERT ( QObject::connect(myViewPort, SIGNAL(vpMouseDoubleClick (QMouseEvent*)),
148 this, SIGNAL(vfMouseDoubleClick(QMouseEvent*))) );
150 QAD_ASSERT ( QObject::connect(myViewPort, SIGNAL(vpKeyPress (QKeyEvent*)),
151 this, SIGNAL(vfKeyPress(QKeyEvent*))) );
152 QAD_ASSERT ( QObject::connect(myViewPort, SIGNAL(vpKeyRelease (QKeyEvent*)),
153 this, SIGNAL(vfKeyRelease(QKeyEvent*))) );
157 Returns widget containing 3D-Viewer
159 QWidget* OCCViewer_ViewFrame::getViewWidget()
161 return (QWidget*)getViewPort();
165 Returns the viewport of this frame
167 OCCViewer_ViewPort* OCCViewer_ViewFrame::getViewPort() const
173 Sets the cursor for the viewframe's viewport
175 void OCCViewer_ViewFrame::setCursor( const QCursor& cursor)
178 myViewPort->QWidget::setCursor(cursor);
182 Returns the current cursor
184 QCursor OCCViewer_ViewFrame::cursor() const
187 return myViewPort->cursor();
188 return QMainWindow::cursor();
192 Set background of the viewport
194 void OCCViewer_ViewFrame::setBackgroundColor( const QColor& color)
197 myViewPort->setBackgroundColor(color);
201 Returns background of the viewport
203 QColor OCCViewer_ViewFrame::backgroundColor() const
206 return myViewPort->backgroundColor();
207 return QMainWindow::backgroundColor();
211 Sets the parent viewer for the window
213 void OCCViewer_ViewFrame::setViewer(OCCViewer_Viewer3d* viewer)
219 Returns the parent viewer for the window
221 OCCViewer_Viewer3d* OCCViewer_ViewFrame::getViewer() const
227 Returns 'true' if viewframe is visible
229 void OCCViewer_ViewFrame::setVisible( bool visible )
231 if ( visible == QWidget::isVisible() )
234 if ( visible ) show();
239 Called when viewframe is about to close
241 void OCCViewer_ViewFrame::closeEvent(QCloseEvent* e)
243 emit vfViewClosing(e); /* notify our viewer */
247 Called when viewframe is resized
249 void OCCViewer_ViewFrame::resizeEvent(QResizeEvent* e)
254 void OCCViewer_ViewFrame::keyPressEvent( QKeyEvent *k )
260 Fits all objects in the active view
262 void OCCViewer_ViewFrame::onViewFitAll()
264 myViewPort->fitAll();
268 Fits all obejcts within a rectangular area of the active view
270 void OCCViewer_ViewFrame::onViewFitArea()
272 myViewPort->activateWindowFit();
273 QAD_Application::getDesktop()->putInfo( tr("PRP_VW3D_SKETCHAREA") );
277 Moves the active view
279 void OCCViewer_ViewFrame::onViewPan()
281 myViewPort->activatePanning();
285 Zooms the active view
287 void OCCViewer_ViewFrame::onViewZoom()
289 myViewPort->activateZoom();
293 Sets a new center of the active view
295 void OCCViewer_ViewFrame::onViewGlobalPan()
297 myViewPort->activateGlobalPanning();
298 QAD_Application::getDesktop()->putInfo( tr("PRP_VW3D_POINTCENTER") );
302 Rotates the active view
304 void OCCViewer_ViewFrame::onViewRotate()
306 myViewPort->activateRotation();
310 Reset the active view
312 void OCCViewer_ViewFrame::onViewReset()
318 Provides front projection of the active view
320 void OCCViewer_ViewFrame::onViewFront()
322 Handle( V3d_View) view3d = ((OCCViewer_ViewPort3d*)myViewPort)->getView();
323 if ( !view3d.IsNull() ) view3d->SetProj (V3d_Xpos);
328 Provides back projection of the active view
330 void OCCViewer_ViewFrame::onViewBack()
332 Handle( V3d_View) view3d = ((OCCViewer_ViewPort3d*)myViewPort)->getView();
333 if ( !view3d.IsNull() ) view3d->SetProj (V3d_Xneg);
338 Provides right projection of the active view
340 void OCCViewer_ViewFrame::onViewRight()
342 Handle( V3d_View) view3d = ((OCCViewer_ViewPort3d*)myViewPort)->getView();
343 if ( !view3d.IsNull() )
344 view3d->SetProj( V3d_Ypos );
349 Provides left projection of the active view
351 void OCCViewer_ViewFrame::onViewLeft()
353 Handle( V3d_View) view3d = ((OCCViewer_ViewPort3d*)myViewPort)->getView();
354 if ( !view3d.IsNull() )
355 view3d->SetProj( V3d_Yneg );
360 Provides bottom projection of the active view
362 void OCCViewer_ViewFrame::onViewBottom()
364 Handle( V3d_View) view3d = ((OCCViewer_ViewPort3d*)myViewPort)->getView();
365 if ( !view3d.IsNull() ) view3d->SetProj(V3d_Zneg);
370 Provides top projection of the active view
372 void OCCViewer_ViewFrame::onViewTop()
374 Handle( V3d_View) view3d = ((OCCViewer_ViewPort3d*)myViewPort)->getView();
375 if ( !view3d.IsNull() ) view3d->SetProj( V3d_Zpos );
380 Display/hide Trihedron
382 void OCCViewer_ViewFrame::onViewTrihedron()
384 if (!myViewer->getAISContext()->IsDisplayed( myViewer->getTrihedron() ))
385 myViewer->getAISContext()->Display( myViewer->getTrihedron() );
387 myViewer->getAISContext()->Erase( myViewer->getTrihedron() );
391 void OCCViewer_ViewFrame::rename( const Handle(SALOME_InteractiveObject)& IObject, QString newName )
393 myViewer->rename(IObject, newName);
396 void OCCViewer_ViewFrame::unHighlightAll()
398 myViewer->unHighlightAll();
401 void OCCViewer_ViewFrame::highlight( const Handle(SALOME_InteractiveObject)& IObject, bool highlight, bool update )
403 myViewer->highlight(IObject, highlight, update);
406 bool OCCViewer_ViewFrame::isInViewer( const Handle(SALOME_InteractiveObject)& IObject )
408 return myViewer->isInViewer( IObject );
411 bool OCCViewer_ViewFrame::isVisible( const Handle(SALOME_InteractiveObject)& IObject )
413 return myViewer->isVisible( IObject );
416 void OCCViewer_ViewFrame::setPopupServer( QAD_Application* App )
418 myViewer->setPopupServer( App );
421 void OCCViewer_ViewFrame::undo(QAD_Study* theStudy, const char* StudyFrameEntry)
423 SALOMEDS::Study_var aStudy = theStudy->getStudyDocument();
424 AIS_ListOfInteractive List1;
425 myViewer->getAISContext()->ObjectsInCollector(List1);
426 AIS_ListIteratorOfListOfInteractive ite1(List1);
427 for( ; ite1.More(); ite1.Next() )
429 Handle(SALOME_InteractiveObject) anObj =
430 Handle(SALOME_InteractiveObject)::DownCast( ite1.Value()->GetOwner() );
432 if ( !anObj.IsNull() &&
434 theStudy->isInViewer( anObj->getEntry(), StudyFrameEntry) )
436 myViewer->getAISContext()->Display( ite1.Value() );
440 AIS_ListOfInteractive List;
441 myViewer->getAISContext()->DisplayedObjects(List);
442 AIS_ListIteratorOfListOfInteractive ite(List);
443 for ( ; ite.More(); ite.Next() )
445 Handle(SALOME_InteractiveObject) anObj =
446 Handle(SALOME_InteractiveObject)::DownCast( ite.Value()->GetOwner() );
448 if ( !anObj.IsNull() &&
450 theStudy->isInViewer( anObj->getEntry(), StudyFrameEntry) )
452 myViewer->getAISContext()->Erase( ite.Value(), true, true );
457 void OCCViewer_ViewFrame::redo(QAD_Study* theStudy, const char* StudyFrameEntry)
459 SALOMEDS::Study_var aStudy = theStudy->getStudyDocument();
460 SALOMEDS::SObject_var RefSO;
461 SALOMEDS::SObject_var SO = aStudy->FindObjectID( StudyFrameEntry );
462 SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(SO);
463 for (; it->More();it->Next()){
464 SALOMEDS::SObject_var CSO= it->Value();
465 if (CSO->ReferencedObject(RefSO))
467 AIS_ListOfInteractive List;
468 myViewer->getAISContext()->ObjectsInCollector(List);
470 AIS_ListIteratorOfListOfInteractive ite(List);
471 for ( ; ite.More(); ite.Next() )
473 Handle(SALOME_InteractiveObject) anObj =
474 Handle(SALOME_InteractiveObject)::DownCast( ite.Value()->GetOwner() );
476 if ( !anObj.IsNull() && anObj->hasEntry() && strcmp( anObj->getEntry(), RefSO->GetID() ) == 0 )
477 myViewer->getAISContext()->Display( ite.Value(), false );
482 AIS_ListOfInteractive List1;
483 myViewer->getAISContext()->DisplayedObjects(List1);
484 AIS_ListIteratorOfListOfInteractive ite1(List1);
485 for ( ; ite1.More(); ite1.Next() )
487 Handle(SALOME_InteractiveObject) anObj =
488 Handle(SALOME_InteractiveObject)::DownCast( ite1.Value()->GetOwner() );
490 if ( !anObj.IsNull() && anObj->hasEntry() && !theStudy->isInViewer( anObj->getEntry(), StudyFrameEntry ) )
491 myViewer->getAISContext()->Erase( ite1.Value(), false, true );
498 Handle(SALOME_InteractiveObject) OCCViewer_ViewFrame::FindIObject(const char* Entry)
500 Handle (AIS_InteractiveContext) ic = myViewer->getAISContext();
502 AIS_ListOfInteractive List;
503 ic->DisplayedObjects(List);
504 AIS_ListOfInteractive List1;
505 ic->ObjectsInCollector(List1);
508 AIS_ListIteratorOfListOfInteractive ite(List);
509 for ( ; ite.More(); ite.Next() )
511 Handle(SALOME_InteractiveObject) anObj =
512 Handle(SALOME_InteractiveObject)::DownCast( ite.Value()->GetOwner() );
514 if ( !anObj.IsNull() && anObj->hasEntry() && strcmp( anObj->getEntry(), Entry ) == 0 )
516 MESSAGE ( "IO found")
520 MESSAGE ( "IO not found")
521 return Handle(SALOME_InteractiveObject)();
525 void OCCViewer_ViewFrame::Display(const Handle(SALOME_InteractiveObject)& IObject, bool update)
527 QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
528 SALOME_Selection* Sel
529 = SALOME_Selection::Selection( myStudy->getSelection() );
531 Handle (AIS_InteractiveContext) ic = myViewer->getAISContext();
533 AIS_ListOfInteractive List;
534 ic->DisplayedObjects(List);
535 AIS_ListOfInteractive List1;
536 ic->ObjectsInCollector(List1);
539 AIS_ListIteratorOfListOfInteractive ite( List );
540 for ( ; ite.More(); ite.Next() )
542 Handle(SALOME_InteractiveObject) anObj =
543 Handle(SALOME_InteractiveObject)::DownCast( ite.Value()->GetOwner() );
545 if ( !anObj.IsNull() && anObj->hasEntry() && anObj->isSame( IObject ) )
547 ic->Display( ite.Value(), false );
548 Sel->AddIObject( anObj, false );
557 void OCCViewer_ViewFrame::DisplayOnly(const Handle(SALOME_InteractiveObject)& IObject)
559 QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
560 SALOME_Selection* Sel
561 = SALOME_Selection::Selection( myStudy->getSelection() );
563 Handle (AIS_InteractiveContext) ic = myViewer->getAISContext();
565 AIS_ListOfInteractive List;
566 ic->DisplayedObjects(List);
567 AIS_ListOfInteractive List1;
568 ic->ObjectsInCollector(List1);
571 AIS_ListIteratorOfListOfInteractive ite( List );
572 for ( ; ite.More(); ite.Next() )
574 Handle(SALOME_InteractiveObject) anObj =
575 Handle(SALOME_InteractiveObject)::DownCast( ite.Value()->GetOwner() );
577 if ( !anObj.IsNull() && anObj->hasEntry() )
579 if ( !anObj->isSame( IObject ) )
581 ic->Erase( ite.Value(), false );
582 Sel->RemoveIObject( anObj, false );
586 ic->Display( ite.Value(), false );
587 Sel->AddIObject( anObj, false );
594 void OCCViewer_ViewFrame::Erase(const Handle(SALOME_InteractiveObject)& IObject, bool update)
596 QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
597 SALOME_Selection* Sel
598 = SALOME_Selection::Selection( myStudy->getSelection() );
600 Handle (AIS_InteractiveContext) ic = myViewer->getAISContext();
602 AIS_ListOfInteractive List;
603 ic->DisplayedObjects(List);
605 AIS_ListIteratorOfListOfInteractive ite( List );
606 for ( ; ite.More(); ite.Next() )
608 Handle(SALOME_InteractiveObject) anObj =
609 Handle(SALOME_InteractiveObject)::DownCast( ite.Value()->GetOwner() );
611 if ( !anObj.IsNull() && anObj->hasEntry() )
613 if ( anObj->isSame( IObject ) )
615 ic->Erase( ite.Value(), false );
616 Sel->RemoveIObject( anObj, false );
626 void OCCViewer_ViewFrame::DisplayAll()
628 myViewer->getAISContext()->DisplayAll(Standard_False,Standard_True);
630 void OCCViewer_ViewFrame::EraseAll()
632 Standard_Boolean isTrihedronDisplayed =
633 myViewer->getAISContext()->IsDisplayed( myViewer->getTrihedron() );
634 myViewer->getAISContext()->EraseAll();
635 if (isTrihedronDisplayed)
636 myViewer->getAISContext()->Display( myViewer->getTrihedron() );
643 void OCCViewer_ViewFrame::Repaint()
646 myViewer->getViewer3d()->Update();
649 //==========================================================
651 * OCCViewer_ViewFrame::getTrihedronSize
652 * Get new an current trihedron size
654 //==========================================================
655 bool OCCViewer_ViewFrame::getTrihedronSize( double& theNewSize, double& theSize )
660 Handle( V3d_View) view3d = ((OCCViewer_ViewPort3d*)myViewPort)->getView();
662 if ( view3d.IsNull() )
665 double Xmin = 0, Ymin = 0, Zmin = 0, Xmax = 0, Ymax = 0, Zmax = 0;
669 view3d->View()->MinMaxValues( Xmin, Ymin, Zmin, Xmax, Ymax, Zmax );
671 if ( Xmin == RealFirst() || Ymin == RealFirst() || Zmin == RealFirst() ||
672 Xmax == RealLast() || Ymax == RealLast() || Zmax == RealLast() )
675 aMaxSide = Xmax - Xmin;
676 if ( aMaxSide < Ymax -Ymin ) aMaxSide = Ymax -Ymin;
677 if ( aMaxSide < Zmax -Zmin ) aMaxSide = Zmax -Zmin;
679 static float aSizeInPercents = 105;
680 QString aSetting = QAD_CONFIG->getSetting("Viewer:TrihedronSize");
681 if (!aSetting.isEmpty())
682 aSizeInPercents = aSetting.toFloat();
684 static float EPS = 5.0E-3;
685 theSize = myViewer->getTrihedron()->Size();
686 theNewSize = aMaxSide*aSizeInPercents / 100.0;
688 return fabs( theNewSize - theSize ) > theSize * EPS ||
689 fabs( theNewSize - theSize) > theNewSize * EPS;
692 void OCCViewer_ViewFrame::AdjustTrihedrons( const bool forced )
694 Handle (AIS_InteractiveContext) ic = myViewer->getAISContext();
696 if ( !myViewer->isTrihedronDisplayed() )
700 AIS_ListOfInteractive List;
701 ic->DisplayedObjects(List);
702 if ( List.First() == List.Last() && List.First() == myViewer->getTrihedron() )
704 myViewer->setTrihedronSize( 100 );
709 double aNewSize = 100, aSize = 100;
710 if ( getTrihedronSize( aNewSize, aSize ) || forced )
711 myViewer->setTrihedronSize( aNewSize );
714 void OCCViewer_ViewFrame::onAdjustTrihedron()
716 AdjustTrihedrons( false );
719 //==========================================================
721 * OCCViewer_ViewFrame::Display
722 * Display presentation
724 //==========================================================
725 void OCCViewer_ViewFrame::Display( const SALOME_OCCPrs* prs )
727 // try do downcast object
728 const OCCViewer_Prs* anOCCPrs = dynamic_cast<const OCCViewer_Prs*>( prs );
729 if ( !anOCCPrs || anOCCPrs->IsNull() )
733 Handle (AIS_InteractiveContext) ic = myViewer->getAISContext();
734 // get all displayed objects
735 AIS_ListOfInteractive List;
736 ic->DisplayedObjects( List );
737 // get objects in he collector
738 AIS_ListOfInteractive ListCollector;
739 ic->ObjectsInCollector( ListCollector );
741 // get objects to be displayed
742 AIS_ListOfInteractive anAISObjects;
743 anOCCPrs->GetObjects( anAISObjects );
745 AIS_ListIteratorOfListOfInteractive aIter( anAISObjects );
746 for ( ; aIter.More(); aIter.Next() ) {
747 Handle(AIS_InteractiveObject) anAIS = aIter.Value();
748 if ( !anAIS.IsNull() ) {
749 // try to find presentation in the viewer
750 bool bDisplayed = false;
751 AIS_ListIteratorOfListOfInteractive ite( List );
752 while ( ite.More() ) {
753 // compare presentations by handles
754 // if the object is already displayed - nothing to do more
755 if ( ite.Value() == anAIS ) {
757 // Deactivate object if necessary
758 if ( !anOCCPrs->ToActivate() )
759 ic->Deactivate( anAIS );
767 // then try to find presentation in the collector
769 ite.Initialize( ListCollector );
770 while ( ite.More() ) {
771 // compare presentations by handles
772 // if the object is in collector - display it
773 if ( ite.Value() == anAIS ) {
774 ic->DisplayFromCollector( anAIS, false );
776 // Deactivate object if necessary
777 if ( !anOCCPrs->ToActivate() )
778 ic->Deactivate( anAIS );
786 // if object is not displayed and not found in the collector - display it
787 if ( anAIS->IsKind( STANDARD_TYPE(AIS_Trihedron) ) )
789 Handle(AIS_Trihedron) aTrh = Handle(AIS_Trihedron)::DownCast( anAIS );
790 double aNewSize = 100, aSize = 100;
791 getTrihedronSize( aNewSize, aSize );
792 aTrh->SetSize( aTrh == myViewer->getTrihedron() ? aNewSize : 0.5 * aNewSize );
795 ic->Display( anAIS, false );
797 // Deactivate object if necessary
798 if ( !anOCCPrs->ToActivate() )
799 ic->Deactivate( anAIS );
804 //==========================================================
806 * OCCViewer_ViewFrame::Erase
809 //==========================================================
810 void OCCViewer_ViewFrame::Erase( const SALOME_OCCPrs* prs, const bool forced )
812 // try do downcast object
813 const OCCViewer_Prs* anOCCPrs = dynamic_cast<const OCCViewer_Prs*>( prs );
814 if ( !anOCCPrs || anOCCPrs->IsNull() )
818 Handle(AIS_InteractiveContext) ic = myViewer->getAISContext();
820 // get objects to be erased
821 AIS_ListOfInteractive anAISObjects;
822 anOCCPrs->GetObjects( anAISObjects );
824 AIS_ListIteratorOfListOfInteractive aIter( anAISObjects );
825 for ( ; aIter.More(); aIter.Next() ) {
826 Handle(AIS_InteractiveObject) anAIS = aIter.Value();
827 if ( !anAIS.IsNull() ) {
828 // erase the object from context : move it to collector
829 ic->Erase( anAIS, false, forced ? false : true );
834 //==========================================================
836 * OCCViewer_ViewFrame::CreatePrs
837 * Create presentation by entry
839 //==========================================================
840 SALOME_Prs* OCCViewer_ViewFrame::CreatePrs( const char* entry )
842 OCCViewer_Prs* prs = new OCCViewer_Prs();
846 Handle(AIS_InteractiveContext) ic = myViewer->getAISContext();
848 // get displayed objects
849 AIS_ListOfInteractive List;
850 ic->DisplayedObjects( List );
851 // get objects in the collector
852 AIS_ListOfInteractive ListCollector;
853 ic->ObjectsInCollector( ListCollector );
854 List.Append( ListCollector );
856 AIS_ListIteratorOfListOfInteractive ite( List );
857 for ( ; ite.More(); ite.Next() )
859 Handle(SALOME_InteractiveObject) anObj =
860 Handle(SALOME_InteractiveObject)::DownCast( ite.Value()->GetOwner() );
862 if ( !anObj.IsNull() && anObj->hasEntry() && strcmp( anObj->getEntry(), entry ) == 0 )
863 prs->AddObject( ite.Value() );
869 //==========================================================
871 * OCCViewer_ViewFrame::LocalSelection
872 * Activates selection of sub shapes
874 //==========================================================
875 void OCCViewer_ViewFrame::LocalSelection( const SALOME_OCCPrs* thePrs, const int theMode )
877 Handle(AIS_InteractiveContext) anIC = myViewer->getAISContext();
879 const OCCViewer_Prs* anOCCPrs = dynamic_cast<const OCCViewer_Prs*>( thePrs );
883 // Open local context if there is no one
884 bool allObjects = thePrs == 0 || thePrs->IsNull();
885 if ( !anIC->HasOpenedContext() ) {
886 anIC->ClearCurrents( false );
887 anIC->OpenLocalContext( allObjects, true, true );
890 AIS_ListOfInteractive anObjs;
891 // Get objects to be activated
893 anIC->DisplayedObjects( anObjs );
895 anOCCPrs->GetObjects( anObjs );
897 // Activate selection of objects from prs
898 AIS_ListIteratorOfListOfInteractive aIter( anObjs );
899 for ( ; aIter.More(); aIter.Next() ) {
900 Handle(AIS_InteractiveObject) anAIS = aIter.Value();
901 if ( !anAIS.IsNull() )
903 if ( anAIS->IsKind( STANDARD_TYPE( AIS_Shape ) ) )
905 anIC->Load( anAIS, -1, false );
906 anIC->Activate( anAIS, AIS_Shape::SelectionMode( (TopAbs_ShapeEnum)theMode ) );
908 else if ( anAIS->DynamicType() != STANDARD_TYPE(AIS_Trihedron) )
910 anIC->Load( anAIS, -1, false );
911 anIC->Activate( anAIS, theMode );
917 //==========================================================
919 * OCCViewer_ViewFrame::GlobalSelection
920 * Deactivates selection of sub shapes
922 //==========================================================
923 void OCCViewer_ViewFrame::GlobalSelection( const bool update ) const
925 Handle(AIS_InteractiveContext) anIC = myViewer->getAISContext();
926 if ( !anIC.IsNull() )
927 anIC->CloseAllContexts( false );
929 anIC->CurrentViewer()->Redraw();
932 //==========================================================
934 * OCCViewer_ViewFrame::BeforeDisplay
935 * Axiluary method called before displaying of objects
937 //==========================================================
938 void OCCViewer_ViewFrame::BeforeDisplay( SALOME_Displayer* d )
940 d->BeforeDisplay( this, SALOME_OCCViewType() );
943 //==========================================================
945 * OCCViewer_ViewFrame::AfterDisplay
946 * Axiluary method called after displaying of objects
948 //==========================================================
949 void OCCViewer_ViewFrame::AfterDisplay( SALOME_Displayer* d )
951 d->AfterDisplay( this, SALOME_OCCViewType() );