2 // File : OCCViewer_ViewFrame.cxx
3 // Created : Wed Mar 20 10:50:22 2002
4 // Author : Nicolas REJNERI
7 // Copyright : Open CASCADE 2002
11 #include "OCCViewer_ViewFrame.h"
12 #include "OCCViewer_Viewer3d.h"
13 #include "OCCViewer_ViewPort.h"
14 #include "OCCViewer_ViewPort3d.h"
17 #include "QAD_Tools.h"
18 #include "QAD_Desktop.h"
19 #include "QAD_ViewFrame.h"
20 #include "QAD_MessageBox.h"
21 #include "QAD_Application.h"
22 #include "utilities.h"
24 #include "SALOME_Selection.h"
25 #include "SALOME_AISShape.hxx"
28 #include <qapplication.h>
30 // Open CASCADE Include
31 #include <V3d_View.hxx>
32 #include <AIS_ListIteratorOfListOfInteractive.hxx>
38 OCCViewer_ViewFrame::OCCViewer_ViewFrame(QWidget* parent, const QString& title)
39 : QAD_ViewFrame (parent, "")
47 OCCViewer_ViewFrame::OCCViewer_ViewFrame( QWidget* parent )
48 : QAD_ViewFrame (parent, "")
56 OCCViewer_ViewFrame::~OCCViewer_ViewFrame()
64 void OCCViewer_ViewFrame::initialize()
67 myViewer = new OCCViewer_Viewer3d( this );
69 /* enable/disable selection */
70 myViewer->enableSelection( true );
71 myViewer->enableMultipleSelection( true );
77 void OCCViewer_ViewFrame::cleanup()
83 Sets the viewport for this frame
85 void OCCViewer_ViewFrame::setViewPort( OCCViewer_ViewPort* view )
89 setCentralWidget ( myViewPort );
93 Inits the viewport for this frame
95 void OCCViewer_ViewFrame::initViewPort()
97 /* Active Key Event */
100 /* Initial attributes */
101 myViewPort->setCursor( cursor() );
102 myViewPort->setBackgroundColor( backgroundColor() );
104 QAD_ASSERT ( QObject::connect(myViewPort, SIGNAL(vpKeyPress (QKeyEvent*)),
105 this, SIGNAL(vfKeyPress(QKeyEvent*))) );
107 /* Listen to my viewport */
108 QAD_ASSERT ( QObject::connect(myViewPort,
109 SIGNAL(vpTransformationStarted (OCCViewer_ViewPort::OperationType)),
111 SIGNAL(vfTransformationStarted(OCCViewer_ViewPort::OperationType))) );
112 QAD_ASSERT ( QObject::connect( myViewPort,
113 SIGNAL(vpTransformationFinished (OCCViewer_ViewPort::OperationType)),
115 SIGNAL(vfTransformationFinished(OCCViewer_ViewPort::OperationType))) );
117 QAD_ASSERT ( QObject::connect(myViewPort, SIGNAL(vpDrawExternal (QPainter*)),
118 this, SIGNAL(vfDrawExternal(QPainter*))) );
119 QAD_ASSERT ( QObject::connect(myViewPort, SIGNAL(vpMousePress (QMouseEvent*)),
120 this, SIGNAL(vfMousePress(QMouseEvent*))) );
121 QAD_ASSERT ( QObject::connect(myViewPort, SIGNAL(vpMouseRelease (QMouseEvent*)),
122 this, SIGNAL(vfMouseRelease(QMouseEvent*))) );
123 QAD_ASSERT ( QObject::connect(myViewPort, SIGNAL(vpMouseMove (QMouseEvent*)),
124 this, SIGNAL(vfMouseMove(QMouseEvent*))) );
125 QAD_ASSERT ( QObject::connect(myViewPort, SIGNAL(vpMouseDoubleClick (QMouseEvent*)),
126 this, SIGNAL(vfMouseDoubleClick(QMouseEvent*))) );
128 QAD_ASSERT ( QObject::connect(myViewPort, SIGNAL(vpKeyPress (QKeyEvent*)),
129 this, SIGNAL(vfKeyPress(QKeyEvent*))) );
130 QAD_ASSERT ( QObject::connect(myViewPort, SIGNAL(vpKeyRelease (QKeyEvent*)),
131 this, SIGNAL(vfKeyRelease(QKeyEvent*))) );
135 Returns widget containing 3D-Viewer
137 QWidget* OCCViewer_ViewFrame::getViewWidget()
139 return (QWidget*)getViewPort();
143 Returns the viewport of this frame
145 OCCViewer_ViewPort* OCCViewer_ViewFrame::getViewPort() const
151 Sets the cursor for the viewframe's viewport
153 void OCCViewer_ViewFrame::setCursor( const QCursor& cursor)
156 myViewPort->QWidget::setCursor(cursor);
160 Returns the current cursor
162 QCursor OCCViewer_ViewFrame::cursor() const
165 return myViewPort->cursor();
166 return QMainWindow::cursor();
170 Set background of the viewport
172 void OCCViewer_ViewFrame::setBackgroundColor( const QColor& color)
175 myViewPort->setBackgroundColor(color);
179 Returns background of the viewport
181 QColor OCCViewer_ViewFrame::backgroundColor() const
184 return myViewPort->backgroundColor();
185 return QMainWindow::backgroundColor();
189 Sets the parent viewer for the window
191 void OCCViewer_ViewFrame::setViewer(OCCViewer_Viewer3d* viewer)
197 Returns the parent viewer for the window
199 OCCViewer_Viewer3d* OCCViewer_ViewFrame::getViewer() const
205 Returns 'true' if viewframe is visible
207 void OCCViewer_ViewFrame::setVisible( bool visible )
209 if ( visible == QWidget::isVisible() )
212 if ( visible ) show();
217 Called when viewframe is about to close
219 void OCCViewer_ViewFrame::closeEvent(QCloseEvent* e)
221 emit vfViewClosing(e); /* notify our viewer */
225 Called when viewframe is resized
227 void OCCViewer_ViewFrame::resizeEvent(QResizeEvent* e)
232 void OCCViewer_ViewFrame::keyPressEvent( QKeyEvent *k )
238 Fits all objects in the active view
240 void OCCViewer_ViewFrame::onViewFitAll()
242 myViewPort->fitAll();
246 Fits all obejcts within a rectangular area of the active view
248 void OCCViewer_ViewFrame::onViewFitArea()
250 myViewPort->activateWindowFit();
251 QAD_Application::getDesktop()->putInfo( tr("PRP_VW3D_SKETCHAREA") );
255 Moves the active view
257 void OCCViewer_ViewFrame::onViewPan()
259 myViewPort->activatePanning();
263 Zooms the active view
265 void OCCViewer_ViewFrame::onViewZoom()
267 myViewPort->activateZoom();
271 Sets a new center of the active view
273 void OCCViewer_ViewFrame::onViewGlobalPan()
275 myViewPort->activateGlobalPanning();
276 QAD_Application::getDesktop()->putInfo( tr("PRP_VW3D_POINTCENTER") );
280 Rotates the active view
282 void OCCViewer_ViewFrame::onViewRotate()
284 myViewPort->activateRotation();
288 Reset the active view
290 void OCCViewer_ViewFrame::onViewReset()
296 Provides front projection of the active view
298 void OCCViewer_ViewFrame::onViewFront()
300 Handle( V3d_View) view3d = ((OCCViewer_ViewPort3d*)myViewPort)->getView();
301 if ( !view3d.IsNull() ) view3d->SetProj (V3d_Xpos);
306 Provides back projection of the active view
308 void OCCViewer_ViewFrame::onViewBack()
310 Handle( V3d_View) view3d = ((OCCViewer_ViewPort3d*)myViewPort)->getView();
311 if ( !view3d.IsNull() ) view3d->SetProj (V3d_Xneg);
316 Provides right projection of the active view
318 void OCCViewer_ViewFrame::onViewRight()
320 Handle( V3d_View) view3d = ((OCCViewer_ViewPort3d*)myViewPort)->getView();
321 if ( !view3d.IsNull() ) view3d->SetProj (V3d_Yneg);
326 Provides left projection of the active view
328 void OCCViewer_ViewFrame::onViewLeft()
330 Handle( V3d_View) view3d = ((OCCViewer_ViewPort3d*)myViewPort)->getView();
331 if ( !view3d.IsNull() ) view3d->SetProj (V3d_Ypos);
336 Provides bottom projection of the active view
338 void OCCViewer_ViewFrame::onViewBottom()
340 Handle( V3d_View) view3d = ((OCCViewer_ViewPort3d*)myViewPort)->getView();
341 if ( !view3d.IsNull() ) view3d->SetProj(V3d_Zneg);
346 Provides top projection of the active view
348 void OCCViewer_ViewFrame::onViewTop()
350 Handle( V3d_View) view3d = ((OCCViewer_ViewPort3d*)myViewPort)->getView();
351 if ( !view3d.IsNull() ) view3d->SetProj( V3d_Zpos );
356 Display/hide Trihedron
358 void OCCViewer_ViewFrame::onViewTrihedron()
360 if (!myViewer->getAISContext()->IsDisplayed( myViewer->getTrihedron() ))
361 myViewer->getAISContext()->Display( myViewer->getTrihedron() );
363 myViewer->getAISContext()->Erase( myViewer->getTrihedron() );
366 void OCCViewer_ViewFrame::rename( const Handle(SALOME_InteractiveObject)& IObject, QString newName )
368 myViewer->rename(IObject, newName);
371 void OCCViewer_ViewFrame::unHighlightAll()
373 myViewer->unHighlightAll();
376 void OCCViewer_ViewFrame::highlight( const Handle(SALOME_InteractiveObject)& IObject, bool highlight, bool update )
378 myViewer->highlight(IObject, highlight, update);
381 bool OCCViewer_ViewFrame::isInViewer( const Handle(SALOME_InteractiveObject)& IObject )
383 return myViewer->isInViewer( IObject );
386 bool OCCViewer_ViewFrame::isVisible( const Handle(SALOME_InteractiveObject)& IObject )
388 return myViewer->isVisible( IObject );
391 void OCCViewer_ViewFrame::setPopupServer( QAD_Application* App )
393 myViewer->setPopupServer( App );
396 void OCCViewer_ViewFrame::undo(SALOMEDS::Study_var aStudy,
397 const char* StudyFrameEntry)
399 AIS_ListOfInteractive List1;
400 myViewer->getAISContext()->ObjectsInCollector(List1);
401 AIS_ListIteratorOfListOfInteractive ite1(List1);
402 while (ite1.More()) {
403 if (ite1.Value()->IsKind(STANDARD_TYPE(SALOME_AISShape))) {
404 Handle(SALOME_AISShape) aSh = Handle(SALOME_AISShape)::DownCast(ite1.Value());
405 if ( aSh->hasIO() ) {
406 Handle(SALOME_InteractiveObject) IO = aSh->getIO();
407 if ( IO->hasEntry() ) {
408 if (!QAD_ViewFrame::isInViewer(aStudy, IO->getEntry(), StudyFrameEntry))
409 myViewer->getAISContext()->Display(aSh);
416 AIS_ListOfInteractive List;
417 myViewer->getAISContext()->DisplayedObjects(List);
418 AIS_ListIteratorOfListOfInteractive ite(List);
420 if (ite.Value()->IsKind(STANDARD_TYPE(SALOME_AISShape))) {
421 Handle(SALOME_AISShape) aSh = Handle(SALOME_AISShape)::DownCast(ite.Value());
422 if ( aSh->hasIO() ) {
423 Handle(SALOME_InteractiveObject) IO = aSh->getIO();
424 if ( IO->hasEntry() ) {
425 if (!QAD_ViewFrame::isInViewer(aStudy, IO->getEntry(), StudyFrameEntry ))
426 myViewer->getAISContext()->Erase(aSh,true,true);
434 void OCCViewer_ViewFrame::redo(SALOMEDS::Study_var aStudy,
435 const char* StudyFrameEntry)
437 SALOMEDS::SObject_var RefSO;
438 SALOMEDS::SObject_var SO = aStudy->FindObjectID( StudyFrameEntry );
439 SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(SO);
440 for (; it->More();it->Next()){
441 SALOMEDS::SObject_var CSO= it->Value();
442 if (CSO->ReferencedObject(RefSO)) {
444 AIS_ListOfInteractive List;
445 myViewer->getAISContext()->ObjectsInCollector(List);
446 AIS_ListIteratorOfListOfInteractive ite(List);
448 if (ite.Value()->IsKind(STANDARD_TYPE(SALOME_AISShape))) {
449 Handle(SALOME_AISShape) aSh = Handle(SALOME_AISShape)::DownCast(ite.Value());
450 if ( aSh->hasIO() ) {
451 Handle(SALOME_InteractiveObject) IO = aSh->getIO();
452 if ( IO->hasEntry() ) {
453 if ( strcmp(IO->getEntry(),RefSO->GetID()) == 0 )
454 myViewer->getAISContext()->Display(aSh, false);
464 AIS_ListOfInteractive List1;
465 myViewer->getAISContext()->DisplayedObjects(List1);
466 AIS_ListIteratorOfListOfInteractive ite1(List1);
467 while (ite1.More()) {
468 if (ite1.Value()->IsKind(STANDARD_TYPE(SALOME_AISShape))) {
469 Handle(SALOME_AISShape) aSh = Handle(SALOME_AISShape)::DownCast(ite1.Value());
470 if ( aSh->hasIO() ) {
471 Handle(SALOME_InteractiveObject) IO = aSh->getIO();
472 if ( IO->hasEntry() ) {
473 if (!QAD_ViewFrame::isInViewer(aStudy, IO->getEntry(), StudyFrameEntry ))
474 myViewer->getAISContext()->Erase(aSh,false,true);
483 void OCCViewer_ViewFrame::SetTrihedronSize( int dim )
485 myViewer->setTrihedronSize( dim );
489 Handle(SALOME_InteractiveObject) OCCViewer_ViewFrame::FindIObject(const char* Entry)
491 Handle(SALOME_InteractiveObject) IO;
492 Handle (AIS_InteractiveContext) ic = myViewer->getAISContext();
494 AIS_ListOfInteractive List;
495 ic->DisplayedObjects(List);
496 AIS_ListOfInteractive List1;
497 ic->ObjectsInCollector(List1);
500 AIS_ListIteratorOfListOfInteractive ite(List);
502 if (ite.Value()->IsKind(STANDARD_TYPE(SALOME_AISShape))) {
503 Handle(SALOME_AISShape) aSh
504 = Handle(SALOME_AISShape)::DownCast(ite.Value());
505 if ( aSh->hasIO() ) {
507 if ( IO->hasEntry() ) {
508 if ( strcmp( IO->getEntry(), Entry ) == 0 ) {
509 MESSAGE ( "IO found")
517 MESSAGE ( "IO not found")
522 void OCCViewer_ViewFrame::Display(const Handle(SALOME_InteractiveObject)& IObject, bool update)
524 QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
525 SALOME_Selection* Sel
526 = SALOME_Selection::Selection( myStudy->getSelection() );
528 Handle (AIS_InteractiveContext) ic = myViewer->getAISContext();
530 AIS_ListOfInteractive List;
531 ic->DisplayedObjects(List);
532 AIS_ListOfInteractive List1;
533 ic->ObjectsInCollector(List1);
536 AIS_ListIteratorOfListOfInteractive ite(List);
538 if (ite.Value()->IsKind(STANDARD_TYPE(SALOME_AISShape))) {
539 Handle(SALOME_AISShape) aSh
540 = Handle(SALOME_AISShape)::DownCast(ite.Value());
541 if ( aSh->hasIO() ) {
542 Handle(SALOME_InteractiveObject) IO = aSh->getIO();
543 if ( IO->isSame( IObject ) ) {
544 ic->Display(aSh, false);
545 // ic->AddOrRemoveCurrentObject(aSh, false); repeated in Viewer3d after next statement
546 Sel->AddIObject(IO, 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);
573 if (ite.Value()->IsKind(STANDARD_TYPE(SALOME_AISShape))) {
574 Handle(SALOME_AISShape) aSh
575 = Handle(SALOME_AISShape)::DownCast(ite.Value());
576 if ( aSh->hasIO() ) {
577 Handle(SALOME_InteractiveObject) IO = aSh->getIO();
578 if ( !IO->isSame( IObject ) ) {
579 ic->Erase(aSh, false);
580 Sel->RemoveIObject(IO, false);
582 ic->Display(aSh, false);
583 Sel->AddIObject(IO, false);
591 void OCCViewer_ViewFrame::Erase(const Handle(SALOME_InteractiveObject)& IObject, bool update)
593 QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
594 SALOME_Selection* Sel
595 = SALOME_Selection::Selection( myStudy->getSelection() );
597 Handle (AIS_InteractiveContext) ic = myViewer->getAISContext();
599 AIS_ListOfInteractive List;
600 ic->DisplayedObjects(List);
601 AIS_ListIteratorOfListOfInteractive ite(List);
604 if (ite.Value()->IsKind(STANDARD_TYPE(SALOME_AISShape)))
606 Handle(SALOME_AISShape) aSh
607 = Handle(SALOME_AISShape)::DownCast(ite.Value());
610 Handle(SALOME_InteractiveObject) IO = aSh->getIO();
611 if ( IO->isSame( IObject ) )
613 ic->Erase(aSh, false);
614 Sel->RemoveIObject(IO, false);
625 void OCCViewer_ViewFrame::DisplayAll()
627 myViewer->getAISContext()->DisplayAll(Standard_False,Standard_True);
629 void OCCViewer_ViewFrame::EraseAll()
631 Standard_Boolean isTrihedronDisplayed =
632 myViewer->getAISContext()->IsDisplayed( myViewer->getTrihedron() );
633 myViewer->getAISContext()->EraseAll();
634 if (isTrihedronDisplayed)
635 myViewer->getAISContext()->Display( myViewer->getTrihedron() );
642 void OCCViewer_ViewFrame::Repaint(){
643 myViewer->getViewer3d()->Update();