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"
47 #include "SALOMEGUI.h"
48 #include "SALOMEDS_Tool.hxx"
52 #include <qapplication.h>
54 // Open CASCADE Include
55 #include <V3d_View.hxx>
56 #include <AIS_ListIteratorOfListOfInteractive.hxx>
57 #include <Visual3d_View.hxx>
60 #include <SALOMEconfig.h>
61 #include CORBA_SERVER_HEADER(SALOMEDS)
62 #include CORBA_SERVER_HEADER(SALOMEDS_Attributes)
66 //=======================================================================
67 // name : getMapOfEntry
68 // Purpose : Convert list of interactive objects in map <entry <--> interactive object>
69 //=======================================================================
70 static void getMapOfEntry( const AIS_ListOfInteractive& theList,
71 QMap< QString, Handle(AIS_InteractiveObject) >& theMap )
73 AIS_ListIteratorOfListOfInteractive anIter( theList );
74 for ( ; anIter.More(); anIter.Next() )
76 Handle(SALOME_InteractiveObject) anIO =
77 Handle(SALOME_InteractiveObject)::DownCast( anIter.Value() );
79 theMap[ anIO->getEntry() ] = anIter.Value();
85 Class : OCCViewer_ViewFrame
86 Description : View frame for Open CASCADE view
90 //=======================================================================
91 // name : OCCViewer_ViewFrame
92 // Purpose : Constructor
93 //=======================================================================
94 OCCViewer_ViewFrame::OCCViewer_ViewFrame( QWidget* parent, const QString& title )
95 : QAD_ViewFrame ( parent, "" )
100 //=======================================================================
101 // name : OCCViewer_ViewFrame
102 // Purpose : Constructor
103 //=======================================================================
104 OCCViewer_ViewFrame::OCCViewer_ViewFrame( QWidget* parent )
105 : QAD_ViewFrame (parent, "")
110 //=======================================================================
111 // name : ~OCCViewer_ViewFrame
112 // Purpose : Destructor
113 //=======================================================================
114 OCCViewer_ViewFrame::~OCCViewer_ViewFrame()
119 //=======================================================================
121 // Purpose : Initialize view frame (called from constructors )
122 //=======================================================================
123 void OCCViewer_ViewFrame::initialize()
126 myViewer = new OCCViewer_Viewer3d( this );
128 /* enable/disable selection */
129 myViewer->enableSelection( true );
130 myViewer->enableMultipleSelection( true );
133 //=======================================================================
135 // Purpose : Cleanup viewframe
136 //=======================================================================
137 void OCCViewer_ViewFrame::cleanup()
141 //=======================================================================
142 // name : setViewPort
143 // Purpose : Sets the viewport for this frame
144 //=======================================================================
145 void OCCViewer_ViewFrame::setViewPort( OCCViewer_ViewPort* view )
149 setCentralWidget ( myViewPort );
152 //=======================================================================
153 // name : initViewPort
154 // Purpose : Inits the viewport for this frame
155 //=======================================================================
156 void OCCViewer_ViewFrame::initViewPort()
158 /* Active Key Event */
162 /* Initial attributes */
164 myViewPort->setCursor( cursor() );
165 myViewPort->setBackgroundColor( backgroundColor() );
167 QAD_ASSERT( QObject::connect(myViewPort, SIGNAL( vpKeyPress ( QKeyEvent* ) ),
168 this, SIGNAL(vfKeyPress(QKeyEvent*))) );
170 /* Listen to my viewport */
172 QAD_ASSERT( connect( myViewPort, SIGNAL( vpTransformationStarted( OCCViewer_ViewPort::OperationType ) ),
173 this, SIGNAL( vfTransformationStarted( OCCViewer_ViewPort::OperationType ) ) ) );
174 QAD_ASSERT( connect( myViewPort, SIGNAL( vpTransformationFinished ( OCCViewer_ViewPort::OperationType ) ),
175 this, SIGNAL( vfTransformationFinished( OCCViewer_ViewPort::OperationType ) ) ) );
177 QAD_ASSERT( connect( myViewPort, SIGNAL( vpDrawExternal( QPainter* ) ),
178 this, SIGNAL( vfDrawExternal( QPainter* ) ) ) );
179 QAD_ASSERT( connect( myViewPort, SIGNAL( vpMousePress( QMouseEvent* ) ),
180 this, SIGNAL( vfMousePress( QMouseEvent* ) ) ) );
181 QAD_ASSERT( connect( myViewPort, SIGNAL( vpMouseRelease( QMouseEvent* ) ),
182 this, SIGNAL( vfMouseRelease( QMouseEvent* ) ) ) );
183 QAD_ASSERT( connect( myViewPort, SIGNAL( vpMouseMove( QMouseEvent* ) ),
184 this, SIGNAL( vfMouseMove( QMouseEvent* ) ) ) );
185 QAD_ASSERT( connect( myViewPort, SIGNAL( vpMouseDoubleClick( QMouseEvent* ) ),
186 this, SIGNAL( vfMouseDoubleClick( QMouseEvent* ) ) ) );
188 QAD_ASSERT( connect( myViewPort, SIGNAL( vpKeyPress( QKeyEvent* ) ),
189 this, SIGNAL( vfKeyPress( QKeyEvent* ) ) ) );
190 QAD_ASSERT( connect( myViewPort, SIGNAL( vpKeyRelease( QKeyEvent* ) ),
191 this, SIGNAL( vfKeyRelease( QKeyEvent* ) ) ) );
194 //=======================================================================
195 // name : getViewWidget
196 // Purpose : Returns widget containing 3D-Viewer
197 //=======================================================================
198 QWidget* OCCViewer_ViewFrame::getViewWidget()
200 return (QWidget*)getViewPort();
203 //=======================================================================
204 // name : getViewPort
205 // Purpose : Returns the viewport of this frame
206 //=======================================================================
207 OCCViewer_ViewPort* OCCViewer_ViewFrame::getViewPort() const
212 //=======================================================================
213 // name : Sets the cursor for the viewframe's viewport
214 // Purpose : setCursor
215 //=======================================================================
216 void OCCViewer_ViewFrame::setCursor( const QCursor& cursor)
219 myViewPort->QWidget::setCursor( cursor );
223 //=======================================================================
225 // Purpose : Returns the current cursor
226 //=======================================================================
227 QCursor OCCViewer_ViewFrame::cursor() const
230 return myViewPort->cursor();
231 return QMainWindow::cursor();
234 //=======================================================================
235 // name : setBackgroundColor
236 // Purpose : Set background of the viewport
237 //=======================================================================
238 void OCCViewer_ViewFrame::setBackgroundColor( const QColor& color)
241 myViewPort->setBackgroundColor( color );
244 //=======================================================================
245 // name : backgroundColor
246 // Purpose : Returns background of the viewport
247 //=======================================================================
248 QColor OCCViewer_ViewFrame::backgroundColor() const
251 return myViewPort->backgroundColor();
252 return QMainWindow::backgroundColor();
255 //=======================================================================
257 // Purpose : Sets the parent viewer for the window
258 //=======================================================================
259 void OCCViewer_ViewFrame::setViewer( OCCViewer_Viewer3d* viewer )
264 //=======================================================================
266 // Purpose : Returns the parent viewer for the window
267 //=======================================================================
268 OCCViewer_Viewer3d* OCCViewer_ViewFrame::getViewer() const
273 //=======================================================================
275 // Purpose : Show/hide view
276 //=======================================================================
277 void OCCViewer_ViewFrame::setVisible( const bool visible )
279 if ( visible == QWidget::isVisible() )
288 //=======================================================================
290 // Purpose : Called when viewframe is about to close
291 //=======================================================================
292 void OCCViewer_ViewFrame::closeEvent( QCloseEvent* e )
294 emit vfViewClosing( e ); /* notify our viewer */
297 //=======================================================================
298 // name : resizeEvent
299 // Purpose : Called when viewframe is resized
300 //=======================================================================
301 void OCCViewer_ViewFrame::resizeEvent( QResizeEvent* e )
306 //=======================================================================
307 // name : keyPressEvent
308 // Purpose : Called when key is pressed
309 //=======================================================================
310 void OCCViewer_ViewFrame::keyPressEvent( QKeyEvent *k )
315 //=======================================================================
316 // name : onViewFitAll
317 // Purpose : Fits all objects in the active view
318 //=======================================================================
319 void OCCViewer_ViewFrame::onViewFitAll()
321 myViewPort->fitAll();
324 //=======================================================================
325 // name : onViewFitArea
326 // Purpose : Fits all obejcts within a rectangular area of the active view
327 //=======================================================================
328 void OCCViewer_ViewFrame::onViewFitArea()
330 myViewPort->activateWindowFit();
331 QAD_Application::getDesktop()->putInfo( tr( "PRP_VW3D_SKETCHAREA" ) );
334 //=======================================================================
336 // Purpose : Moves the active view
337 //=======================================================================
338 void OCCViewer_ViewFrame::onViewPan()
340 myViewPort->activatePanning();
343 //=======================================================================
345 // Purpose : Zooms the active view
346 //=======================================================================
347 void OCCViewer_ViewFrame::onViewZoom()
349 myViewPort->activateZoom();
352 //=======================================================================
353 // name : onViewGlobalPan
354 // Purpose : Sets a new center of the active view
355 //=======================================================================
356 void OCCViewer_ViewFrame::onViewGlobalPan()
358 myViewPort->activateGlobalPanning();
359 QAD_Application::getDesktop()->putInfo( tr("PRP_VW3D_POINTCENTER") );
362 //=======================================================================
363 // name : onViewRotate
364 // Purpose : Rotates the active view
365 //=======================================================================
366 void OCCViewer_ViewFrame::onViewRotate()
368 myViewPort->activateRotation();
371 //=======================================================================
372 // name : onViewReset
373 // Purpose : Reset the active view
374 //=======================================================================
375 void OCCViewer_ViewFrame::onViewReset()
380 //=======================================================================
381 // name : onViewFront
382 // Purpose : Provides front projection of the active view
383 //=======================================================================
384 void OCCViewer_ViewFrame::onViewFront()
386 Handle( V3d_View) view3d = ((OCCViewer_ViewPort3d*)myViewPort)->getView();
387 if ( !view3d.IsNull() ) view3d->SetProj (V3d_Xpos);
391 //=======================================================================
393 // Purpose : Provides back projection of the active view
394 //=======================================================================
395 void OCCViewer_ViewFrame::onViewBack()
397 Handle( V3d_View) view3d = ((OCCViewer_ViewPort3d*)myViewPort)->getView();
398 if ( !view3d.IsNull() ) view3d->SetProj (V3d_Xneg);
402 //=======================================================================
403 // name : onViewRight
404 // Purpose : Provides right projection of the active view
405 //=======================================================================
406 void OCCViewer_ViewFrame::onViewRight()
408 Handle( V3d_View) view3d = ((OCCViewer_ViewPort3d*)myViewPort)->getView();
409 if ( !view3d.IsNull() )
410 view3d->SetProj( V3d_Ypos );
414 //=======================================================================
416 // Purpose : Provides left projection of the active view
417 //=======================================================================
418 void OCCViewer_ViewFrame::onViewLeft()
420 Handle( V3d_View) view3d = ((OCCViewer_ViewPort3d*)myViewPort)->getView();
421 if ( !view3d.IsNull() )
422 view3d->SetProj( V3d_Yneg );
426 //=======================================================================
427 // name : onViewBottom
428 // Purpose : Provides bottom projection of the active view
429 //=======================================================================
430 void OCCViewer_ViewFrame::onViewBottom()
432 Handle( V3d_View) view3d = ((OCCViewer_ViewPort3d*)myViewPort)->getView();
433 if ( !view3d.IsNull() ) view3d->SetProj(V3d_Zneg);
437 //=======================================================================
439 // Purpose : Provides top projection of the active view
440 //=======================================================================
441 void OCCViewer_ViewFrame::onViewTop()
443 Handle( V3d_View) view3d = ((OCCViewer_ViewPort3d*)myViewPort)->getView();
444 if ( !view3d.IsNull() ) view3d->SetProj( V3d_Zpos );
448 //=======================================================================
449 // name : onViewTrihedron
450 // Purpose : Display/hide Trihedron
451 //=======================================================================
452 void OCCViewer_ViewFrame::onViewTrihedron()
454 if (!myViewer->getAISContext()->IsDisplayed( myViewer->getTrihedron() ))
455 myViewer->getAISContext()->Display( myViewer->getTrihedron() );
457 myViewer->getAISContext()->Erase( myViewer->getTrihedron() );
461 //=======================================================================
463 // Purpose : Rename entry object
464 //=======================================================================
465 void OCCViewer_ViewFrame::rename( const Handle(SALOME_InteractiveObject)& IObject,
466 const QString newName )
468 myViewer->rename(IObject, newName);
471 //=======================================================================
472 // name : unHighlightAll
473 // Purpose : Unhighlight all objects
474 //=======================================================================
475 void OCCViewer_ViewFrame::unHighlightAll()
477 myViewer->unHighlightAll();
480 //=======================================================================
482 // Purpose : Highlight object
483 //=======================================================================
484 void OCCViewer_ViewFrame::highlight( const Handle(SALOME_InteractiveObject)& IObject,
485 const bool highlight,
488 myViewer->highlight( IObject, highlight, update );
491 //=======================================================================
493 // Purpose : Magic function
494 //=======================================================================
495 bool OCCViewer_ViewFrame::isInViewer( const Handle(SALOME_InteractiveObject)& IObject )
497 return myViewer->isInViewer( IObject );
500 //=======================================================================
502 // Purpose : Verify whether object is visible
503 //=======================================================================
504 bool OCCViewer_ViewFrame::isVisible( const Handle(SALOME_InteractiveObject)& IObject )
506 return myViewer->isVisible( IObject );
509 //=======================================================================
510 // name : setPopupServer
511 // Purpose : Set popup server
512 //=======================================================================
513 void OCCViewer_ViewFrame::setPopupServer( QAD_Application* App )
515 myViewer->setPopupServer( App );
518 //=======================================================================
519 // name : redisplayAll
520 // Purpose : Redisplay all objects of active component in accordance with
521 // their display flags
522 //=======================================================================
523 void OCCViewer_ViewFrame::redisplayAll( QAD_Study* theQADStudy, const bool theToUpdate )
525 SALOMEDS::Study_var aStudy = theQADStudy->getStudyDocument();
526 QAD_Desktop* aDesktop = QAD_Application::getDesktop();
527 SALOMEGUI* aGUI = aDesktop->getActiveGUI();
528 const QString& aCompName = aDesktop->getComponentDataType();
529 SALOMEDS::SObject_var aComponent =
530 SALOMEDS::SObject::_narrow( aStudy->FindComponent ( aCompName.latin1() ) );
532 if ( aComponent->_is_nil() )
535 Handle(AIS_InteractiveContext) anIC = myViewer->getAISContext();
536 bool isTrhDisplayed = anIC->IsDisplayed( myViewer->getTrihedron() );
538 anIC->DisplayAll( true, false );
539 anIC->EraseAll( false, false );
541 if ( isTrhDisplayed )
542 anIC->Display( myViewer->getTrihedron(), false );
544 std::list<SALOMEDS::SObject_var> aList;
545 SALOMEDS_Tool::GetAllChildren( aStudy, aComponent, aList );
547 std::list<SALOMEDS::SObject_var>::iterator anIter = aList.begin();
548 for ( ; anIter != aList.end(); ++anIter )
550 SALOMEDS::SObject_var anObj = (*anIter);
551 if ( ToolsGUI::GetVisibility( aStudy, anObj, this ) )
553 Handle(SALOME_InteractiveObject) anIObj = new SALOME_InteractiveObject();
554 anIObj->setEntry( anObj->GetID() );
555 aGUI->BuildPresentation( anIObj, this );
563 //=======================================================================
565 // Purpose : Redisplay all objects of active component in accordance with
566 // their display flags. Called when undo operation is complited
567 //=======================================================================
568 void OCCViewer_ViewFrame::undo( QAD_Study* theQADStudy, const char* )
570 redisplayAll( theQADStudy );
573 //=======================================================================
575 // Purpose : Redisplay all objects of active component in accordance with
576 // their display flags. Called when undo operation is complited
577 //=======================================================================
578 void OCCViewer_ViewFrame::redo( QAD_Study* theQADStudy, const char* )
580 redisplayAll( theQADStudy );
583 //=======================================================================
584 // name : FindIObject
585 // Purpose : Find in context SALOME_InteractiveObject by entry
586 //=======================================================================
587 Handle(SALOME_InteractiveObject) OCCViewer_ViewFrame::FindIObject( const char* Entry )
589 Handle (AIS_InteractiveContext) ic = myViewer->getAISContext();
591 AIS_ListOfInteractive List;
592 ic->DisplayedObjects( List );
593 AIS_ListOfInteractive List1;
594 ic->ObjectsInCollector( List1 );
595 List.Append( List1 );
597 AIS_ListIteratorOfListOfInteractive ite( List );
598 for ( ; ite.More(); ite.Next() )
600 Handle(SALOME_InteractiveObject) anObj =
601 Handle(SALOME_InteractiveObject)::DownCast( ite.Value()->GetOwner() );
603 if ( !anObj.IsNull() && anObj->hasEntry() && strcmp( anObj->getEntry(), Entry ) == 0 )
605 MESSAGE ( "IO found")
609 MESSAGE ( "IO not found")
610 return Handle(SALOME_InteractiveObject)();
613 //=======================================================================
615 // Purpose : Display object
616 //=======================================================================
617 void OCCViewer_ViewFrame::Display( const Handle(SALOME_InteractiveObject)& theIObject,
620 if ( theIObject.IsNull() )
623 QAD_Study* aQADStudy = QAD_Application::getDesktop()->getActiveStudy();
624 SALOME_Selection* aSel = SALOME_Selection::Selection( aQADStudy->getSelection() );
625 SALOMEDS::Study_var aStudy = aQADStudy->getStudyDocument();
627 Handle(AIS_InteractiveContext) anIC = myViewer->getAISContext();
629 AIS_ListOfInteractive aList;
630 anIC->ObjectsInCollector( aList );
631 AIS_ListIteratorOfListOfInteractive anIter( aList );
632 for ( ; anIter.More(); anIter.Next() )
634 Handle(SALOME_InteractiveObject) anObj =
635 Handle(SALOME_InteractiveObject)::DownCast( anIter.Value()->GetOwner() );
637 if ( !anObj.IsNull() && anObj->hasEntry() && anObj->isSame( theIObject ) )
639 anIC->Display( anIter.Value(), false );
640 aSel->AddIObject( anObj, false );
641 ToolsGUI::SetVisibility( aStudy, anObj->getEntry(), true, this );
650 //=======================================================================
651 // name : DisplayOnly
652 // Purpose : Display object and erase all other ones
653 //=======================================================================
654 void OCCViewer_ViewFrame::DisplayOnly( const Handle(SALOME_InteractiveObject)& theIO )
660 //=======================================================================
662 // Purpose : Erase object
663 //=======================================================================
664 void OCCViewer_ViewFrame::Erase( const Handle(SALOME_InteractiveObject)& theIObject,
667 QAD_Study* aStudy = QAD_Application::getDesktop()->getActiveStudy();
668 SALOME_Selection* aSel = SALOME_Selection::Selection( aStudy->getSelection() );
670 Handle(AIS_InteractiveContext) anIC = myViewer->getAISContext();
672 AIS_ListOfInteractive aList;
673 anIC->DisplayedObjects( aList );
675 AIS_ListIteratorOfListOfInteractive ite( aList );
676 for ( ; ite.More(); ite.Next() )
678 Handle(SALOME_InteractiveObject) anObj =
679 Handle(SALOME_InteractiveObject)::DownCast( ite.Value()->GetOwner() );
681 if ( !anObj.IsNull() && anObj->hasEntry() )
683 if ( anObj->isSame( theIObject ) )
685 anIC->Erase( ite.Value(), false );
686 aSel->RemoveIObject( anObj, false );
687 ToolsGUI::SetVisibility( aStudy->getStudyDocument(), anObj->getEntry(), false, this );
697 //=======================================================================
699 // Purpose : Display all objects of active component
700 //=======================================================================
701 void OCCViewer_ViewFrame::DisplayAll()
703 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
704 QAD_Desktop* aDesktop = QAD_Application::getDesktop();
705 SALOMEGUI* aGUI = aDesktop->getActiveGUI();
706 const QString& aCompName = aDesktop->getComponentDataType();
707 SALOMEDS::SObject_var aComponent =
708 SALOMEDS::SObject::_narrow( aStudy->FindComponent ( aCompName.latin1() ) );
710 if ( aComponent->_is_nil() )
713 Handle(AIS_InteractiveContext) anIC = myViewer->getAISContext();
715 AIS_ListOfInteractive aDispList;
716 AIS_ListOfInteractive aCollList;
717 anIC->DisplayedObjects( aDispList );
718 anIC->ObjectsInCollector( aCollList );
720 QMap< QString, Handle(AIS_InteractiveObject) > aDispMap;
721 QMap< QString, Handle(AIS_InteractiveObject) > aCollMap;
722 getMapOfEntry( aDispList, aDispMap );
723 getMapOfEntry( aCollList, aCollMap );
725 std::list<SALOMEDS::SObject_var> aList;
726 SALOMEDS_Tool::GetAllChildren( aStudy, aComponent, aList );
728 std::list<SALOMEDS::SObject_var>::iterator anIter = aList.begin();
729 for ( ; anIter != aList.end(); ++anIter )
731 SALOMEDS::SObject_var anObj = (*anIter);
732 if ( anObj->_is_nil() )
735 const char* aEntry = anObj->GetID();
736 if ( aCollMap.contains( aEntry ) )
738 anIC->DisplayFromCollector( aCollMap[ aEntry ], false );
739 ToolsGUI::SetVisibility( aStudy, aEntry, true, this );
741 else if ( !aDispMap.contains( aEntry ) )
743 Handle(SALOME_InteractiveObject) anIObj = new SALOME_InteractiveObject();
744 anIObj->setEntry( anObj->GetID() );
745 aGUI->BuildPresentation( anIObj, this );
752 //=======================================================================
754 // Purpose : Erase all objects
755 //=======================================================================
756 void OCCViewer_ViewFrame::EraseAll()
758 SALOMEDS::Study_var aStudy =
759 QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
761 Standard_Boolean isTrihedronDisplayed =
762 myViewer->getAISContext()->IsDisplayed( myViewer->getTrihedron() );
764 Handle(AIS_InteractiveContext) anIC = myViewer->getAISContext();
766 AIS_ListOfInteractive aList;
767 anIC->DisplayedObjects( aList );
768 AIS_ListIteratorOfListOfInteractive anIter( aList );
769 for ( ; anIter.More(); anIter.Next() )
771 if ( anIC->IsDisplayed( myViewer->getTrihedron() ) &&
772 anIter.Value()->DynamicType() == STANDARD_TYPE( AIS_Trihedron ) )
775 Handle(AIS_InteractiveObject) anIO = anIter.Value();
776 anIC->Erase( anIO, false, true );
778 Handle(SALOME_InteractiveObject) anObj =
779 Handle(SALOME_InteractiveObject)::DownCast( anIO->GetOwner() );
781 if ( !anObj.IsNull() && anObj->hasEntry() )
782 ToolsGUI::SetVisibility( aStudy, anObj->getEntry(), false, this );
785 if ( isTrihedronDisplayed )
786 myViewer->getAISContext()->Display( myViewer->getTrihedron() );
791 //=======================================================================
793 // Purpose : Uodate view
794 //=======================================================================
795 void OCCViewer_ViewFrame::Repaint()
798 myViewer->getViewer3d()->Update();
801 //=======================================================================
802 // name : getTrihedronSize
803 // Purpose : Get new and current trihedron size corresponding to the
804 // current model size
805 //=======================================================================
806 bool OCCViewer_ViewFrame::getTrihedronSize( double& theNewSize, double& theSize )
811 Handle( V3d_View) view3d = ((OCCViewer_ViewPort3d*)myViewPort)->getView();
813 if ( view3d.IsNull() )
816 double Xmin = 0, Ymin = 0, Zmin = 0, Xmax = 0, Ymax = 0, Zmax = 0;
819 view3d->View()->MinMaxValues( Xmin, Ymin, Zmin, Xmax, Ymax, Zmax );
821 if ( Xmin == RealFirst() || Ymin == RealFirst() || Zmin == RealFirst() ||
822 Xmax == RealLast() || Ymax == RealLast() || Zmax == RealLast() )
825 aMaxSide = Xmax - Xmin;
826 if ( aMaxSide < Ymax -Ymin ) aMaxSide = Ymax -Ymin;
827 if ( aMaxSide < Zmax -Zmin ) aMaxSide = Zmax -Zmin;
829 static float aSizeInPercents = 105;
830 QString aSetting = QAD_CONFIG->getSetting("Viewer:TrihedronSize");
831 if (!aSetting.isEmpty())
832 aSizeInPercents = aSetting.toFloat();
834 static float EPS = 5.0E-3;
835 theSize = myViewer->getTrihedron()->Size();
836 theNewSize = aMaxSide*aSizeInPercents / 100.0;
838 return fabs( theNewSize - theSize ) > theSize * EPS ||
839 fabs( theNewSize - theSize) > theNewSize * EPS;
842 //=======================================================================
843 // name : AdjustTrihedrons
844 // Purpose : Adjust trihedron size in accordance with size of model
845 //=======================================================================
846 void OCCViewer_ViewFrame::AdjustTrihedrons( const bool forced )
848 Handle (AIS_InteractiveContext) ic = myViewer->getAISContext();
850 if ( !myViewer->isTrihedronDisplayed() )
854 AIS_ListOfInteractive List;
855 ic->DisplayedObjects(List);
856 if ( List.First() == List.Last() && List.First() == myViewer->getTrihedron() )
858 myViewer->setTrihedronSize( 100 );
863 double aNewSize = 100, aSize = 100;
864 if ( getTrihedronSize( aNewSize, aSize ) || forced )
865 myViewer->setTrihedronSize( aNewSize );
868 //=======================================================================
869 // name : onAdjustTrihedron
870 // Purpose : Slot. Called when trihedrons must be resized
871 //=======================================================================
872 void OCCViewer_ViewFrame::onAdjustTrihedron()
874 AdjustTrihedrons( false );
877 //=======================================================================
879 // Purpose : Display presentation
880 //=======================================================================
881 void OCCViewer_ViewFrame::Display( const SALOME_OCCPrs* prs )
883 // try do downcast object
884 const OCCViewer_Prs* anOCCPrs = dynamic_cast<const OCCViewer_Prs*>( prs );
885 if ( !anOCCPrs || anOCCPrs->IsNull() )
889 Handle (AIS_InteractiveContext) ic = myViewer->getAISContext();
890 // get all displayed objects
891 AIS_ListOfInteractive List;
892 ic->DisplayedObjects( List );
893 // get objects in the collector
894 AIS_ListOfInteractive ListCollector;
895 ic->ObjectsInCollector( ListCollector );
897 // get objects to be displayed
898 AIS_ListOfInteractive anAISObjects;
899 anOCCPrs->GetObjects( anAISObjects );
901 AIS_ListIteratorOfListOfInteractive aIter( anAISObjects );
902 for ( ; aIter.More(); aIter.Next() )
904 Handle(AIS_InteractiveObject) anAIS = aIter.Value();
905 if ( !anAIS.IsNull() )
907 // try to find presentation in the viewer
908 bool bDisplayed = false;
909 AIS_ListIteratorOfListOfInteractive ite( List );
910 for ( ; ite.More(); ite.Next() )
912 // compare presentations by handles
913 // if the object is already displayed - nothing to do more
914 if ( ite.Value() == anAIS )
916 // Deactivate object if necessary
917 if ( !anOCCPrs->ToActivate() )
918 ic->Deactivate( anAIS );
927 // then try to find presentation in the collector
929 ite.Initialize( ListCollector );
930 for ( ; ite.More(); ite.Next() )
932 // compare presentations by handles
933 // if the object is in collector - display it
934 if ( ite.Value() == anAIS )
936 ic->DisplayFromCollector( anAIS, false );
938 // Deactivate object if necessary
939 if ( !anOCCPrs->ToActivate() )
940 ic->Deactivate( anAIS );
943 // Set visibility flag
944 Handle(SALOME_InteractiveObject) anObj =
945 Handle(SALOME_InteractiveObject)::DownCast( anAIS->GetOwner() );
946 if ( !anObj.IsNull() && anObj->hasEntry() )
948 SALOMEDS::Study_var aStudy =
949 QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
950 ToolsGUI::SetVisibility( aStudy, anObj->getEntry(), true, this );
959 // if object is not displayed and not found in the collector - display it
960 if ( anAIS->IsKind( STANDARD_TYPE(AIS_Trihedron) ) )
962 Handle(AIS_Trihedron) aTrh = Handle(AIS_Trihedron)::DownCast( anAIS );
963 double aNewSize = 100, aSize = 100;
964 getTrihedronSize( aNewSize, aSize );
965 aTrh->SetSize( aTrh == myViewer->getTrihedron() ? aNewSize : 0.5 * aNewSize );
968 ic->Display( anAIS, false );
970 // Set visibility flag
971 Handle(SALOME_InteractiveObject) anObj =
972 Handle(SALOME_InteractiveObject)::DownCast( anAIS->GetOwner() );
973 if ( !anObj.IsNull() && anObj->hasEntry() )
975 SALOMEDS::Study_var aStudy =
976 QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
977 ToolsGUI::SetVisibility( aStudy, anObj->getEntry(), true, this );
980 // Deactivate object if necessary
981 if ( !anOCCPrs->ToActivate() )
982 ic->Deactivate( anAIS );
987 //=======================================================================
989 // Purpose : Erase presentation
990 //=======================================================================
991 void OCCViewer_ViewFrame::Erase( const SALOME_OCCPrs* prs, const bool forced )
993 // try do downcast object
994 const OCCViewer_Prs* anOCCPrs = dynamic_cast<const OCCViewer_Prs*>( prs );
995 if ( !anOCCPrs || anOCCPrs->IsNull() )
999 Handle(AIS_InteractiveContext) ic = myViewer->getAISContext();
1001 // get objects to be erased
1002 AIS_ListOfInteractive anAISObjects;
1003 anOCCPrs->GetObjects( anAISObjects );
1005 AIS_ListIteratorOfListOfInteractive aIter( anAISObjects );
1006 for ( ; aIter.More(); aIter.Next() ) {
1007 Handle(AIS_InteractiveObject) anAIS = aIter.Value();
1008 if ( !anAIS.IsNull() ) {
1009 // erase the object from context : move it to collector
1010 ic->Erase( anAIS, false, forced ? false : true );
1012 // Set visibility flag if necessary
1015 Handle(SALOME_InteractiveObject) anObj =
1016 Handle(SALOME_InteractiveObject)::DownCast( anAIS->GetOwner() );
1017 if ( !anObj.IsNull() && anObj->hasEntry() )
1019 SALOMEDS::Study_var aStudy =
1020 QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
1021 ToolsGUI::SetVisibility( aStudy, anObj->getEntry(), true, this );
1028 //=======================================================================
1030 // Purpose : Create presentation corresponding to the entry
1031 //=======================================================================
1032 SALOME_Prs* OCCViewer_ViewFrame::CreatePrs( const char* entry )
1034 OCCViewer_Prs* prs = new OCCViewer_Prs();
1038 Handle(AIS_InteractiveContext) ic = myViewer->getAISContext();
1040 // get displayed objects
1041 AIS_ListOfInteractive List;
1042 ic->DisplayedObjects( List );
1043 // get objects in the collector
1044 AIS_ListOfInteractive ListCollector;
1045 ic->ObjectsInCollector( ListCollector );
1046 List.Append( ListCollector );
1048 AIS_ListIteratorOfListOfInteractive ite( List );
1049 for ( ; ite.More(); ite.Next() )
1051 Handle(SALOME_InteractiveObject) anObj =
1052 Handle(SALOME_InteractiveObject)::DownCast( ite.Value()->GetOwner() );
1054 if ( !anObj.IsNull() && anObj->hasEntry() && strcmp( anObj->getEntry(), entry ) == 0 )
1055 prs->AddObject( ite.Value() );
1061 //=======================================================================
1062 // name : LocalSelection
1063 // Purpose : Activates selection of sub shapes
1064 //=======================================================================
1065 void OCCViewer_ViewFrame::LocalSelection( const SALOME_OCCPrs* thePrs, const int theMode )
1067 Handle(AIS_InteractiveContext) anIC = myViewer->getAISContext();
1069 const OCCViewer_Prs* anOCCPrs = dynamic_cast<const OCCViewer_Prs*>( thePrs );
1070 if ( anIC.IsNull() )
1073 // Open local context if there is no one
1074 bool allObjects = thePrs == 0 || thePrs->IsNull();
1075 if ( !anIC->HasOpenedContext() ) {
1076 anIC->ClearCurrents( false );
1077 anIC->OpenLocalContext( allObjects, true, true );
1080 AIS_ListOfInteractive anObjs;
1081 // Get objects to be activated
1083 anIC->DisplayedObjects( anObjs );
1085 anOCCPrs->GetObjects( anObjs );
1087 // Activate selection of objects from prs
1088 AIS_ListIteratorOfListOfInteractive aIter( anObjs );
1089 for ( ; aIter.More(); aIter.Next() ) {
1090 Handle(AIS_InteractiveObject) anAIS = aIter.Value();
1091 if ( !anAIS.IsNull() )
1093 if ( anAIS->IsKind( STANDARD_TYPE( AIS_Shape ) ) )
1095 anIC->Load( anAIS, -1, false );
1096 anIC->Activate( anAIS, AIS_Shape::SelectionMode( (TopAbs_ShapeEnum)theMode ) );
1098 else if ( anAIS->DynamicType() != STANDARD_TYPE(AIS_Trihedron) )
1100 anIC->Load( anAIS, -1, false );
1101 anIC->Activate( anAIS, theMode );
1107 //=======================================================================
1108 // name : GlobalSelection
1109 // Purpose : Deactivates selection of sub shapes
1110 //=======================================================================
1111 void OCCViewer_ViewFrame::GlobalSelection( const bool update ) const
1113 Handle(AIS_InteractiveContext) anIC = myViewer->getAISContext();
1114 if ( !anIC.IsNull() )
1115 anIC->CloseAllContexts( false );
1117 anIC->CurrentViewer()->Redraw();
1120 //=======================================================================
1121 // name : BeforeDisplay
1122 // Purpose : Axiluary method called before displaying of objects
1123 //=======================================================================
1124 void OCCViewer_ViewFrame::BeforeDisplay( SALOME_Displayer* d )
1126 d->BeforeDisplay( this, SALOME_OCCViewType() );
1129 //=======================================================================
1130 // name : AfterDisplay
1131 // Purpose : Axiluary method called after displaying of objects
1132 //=======================================================================
1133 void OCCViewer_ViewFrame::AfterDisplay( SALOME_Displayer* d )
1135 d->AfterDisplay( this, SALOME_OCCViewType() );
1138 #define INCREMENT_FOR_OP 10
1140 //=======================================================================
1142 // Purpose : Performs incremental panning to the left
1143 //=======================================================================
1144 void OCCViewer_ViewFrame::onPanLeft()
1146 myViewPort->incrementalPan( -INCREMENT_FOR_OP, 0 );
1149 //=======================================================================
1150 // name : onPanRight
1151 // Purpose : Performs incremental panning to the right
1152 //=======================================================================
1153 void OCCViewer_ViewFrame::onPanRight()
1155 myViewPort->incrementalPan( INCREMENT_FOR_OP, 0 );
1158 //=======================================================================
1160 // Purpose : Performs incremental panning to the top
1161 //=======================================================================
1162 void OCCViewer_ViewFrame::onPanUp()
1164 myViewPort->incrementalPan( 0, INCREMENT_FOR_OP );
1167 //=======================================================================
1169 // Purpose : Performs incremental panning to the bottom
1170 //=======================================================================
1171 void OCCViewer_ViewFrame::onPanDown()
1173 myViewPort->incrementalPan( 0, -INCREMENT_FOR_OP );
1176 //=======================================================================
1178 // Purpose : Performs incremental zooming in
1179 //=======================================================================
1180 void OCCViewer_ViewFrame::onZoomIn()
1182 myViewPort->incrementalZoom( INCREMENT_FOR_OP );
1185 //=======================================================================
1187 // Purpose : Performs incremental zooming out
1188 //=======================================================================
1189 void OCCViewer_ViewFrame::onZoomOut()
1191 myViewPort->incrementalZoom( -INCREMENT_FOR_OP );
1194 //=======================================================================
1195 // name : onRotateLeft
1196 // Purpose : Performs incremental rotating to the left
1197 //=======================================================================
1198 void OCCViewer_ViewFrame::onRotateLeft()
1200 myViewPort->incrementalRotate( -INCREMENT_FOR_OP, 0 );
1203 //=======================================================================
1204 // name : onRotateRight
1205 // Purpose : Performs incremental rotating to the right
1206 //=======================================================================
1207 void OCCViewer_ViewFrame::onRotateRight()
1209 myViewPort->incrementalRotate( INCREMENT_FOR_OP, 0 );
1212 //=======================================================================
1213 // name : onRotateUp
1214 // Purpose : Performs incremental rotating to the top
1215 //=======================================================================
1216 void OCCViewer_ViewFrame::onRotateUp()
1218 myViewPort->incrementalRotate( 0, -INCREMENT_FOR_OP );
1221 //=======================================================================
1222 // name : onRotateDown
1223 // Purpose : Performs incremental rotating to the bottom
1224 //=======================================================================
1225 void OCCViewer_ViewFrame::onRotateDown()
1227 myViewPort->incrementalRotate( 0, INCREMENT_FOR_OP );