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"
36 #include "QAD_Config.h"
37 #include "QAD_Desktop.h"
38 #include "QAD_Settings.h"
39 #include "QAD_LeftFrame.h"
40 #include "OCCViewer_ViewPort3d.h"
41 #include "QAD_RightFrame.h"
42 #include "QAD_MessageBox.h"
43 #include "QAD_Application.h"
45 #include "SALOME_Selection.h"
46 #include "SALOME_InteractiveObject.hxx"
47 #include "SALOME_ListIteratorOfListIO.hxx"
49 #include "SALOME_AISShape.hxx"
50 #include "SALOME_AISObject.hxx"
52 #include "utilities.h"
54 // Open CASCADE Includes
55 #include <Geom_Axis2Placement.hxx>
56 #include <AIS_ListOfInteractive.hxx>
57 #include <AIS_ListIteratorOfListOfInteractive.hxx>
63 OCCViewer_Viewer3d::OCCViewer_Viewer3d(OCCViewer_ViewFrame* vf) :
67 if ( myV3dViewer.IsNull() )
68 createViewer3d(); /* create viewer */
70 QString BackgroundColorRed = QAD_CONFIG->getSetting("OCCViewer:BackgroundColorRed");
71 QString BackgroundColorGreen = QAD_CONFIG->getSetting("OCCViewer:BackgroundColorGreen");
72 QString BackgroundColorBlue = QAD_CONFIG->getSetting("OCCViewer:BackgroundColorBlue");
74 if( !BackgroundColorRed.isEmpty() && !BackgroundColorGreen.isEmpty() && !BackgroundColorBlue.isEmpty() )
75 myBackColor = QColor(BackgroundColorRed.toInt(),
76 BackgroundColorGreen.toInt(),
77 BackgroundColorBlue.toInt());
79 myBackColor = QColor(35, 136, 145);
82 myViewFrame->setViewPort ( new OCCViewer_ViewPort3d( myViewFrame, myV3dViewer ) );
83 myViewFrame->setViewer(this);
85 /* properties settings */
86 // if ( !myIcon.isNull() )
87 // myStudyFrame->setIcon( myIcon );
89 myViewFrame->setCursor( myCursor );
90 myViewFrame->setBackgroundColor( myBackColor );
92 if ( myAISContext.IsNull() ) {
93 /* create interactive manager */
94 myAISContext = new AIS_InteractiveContext ( myV3dViewer, myV3dCollector );
96 myAISContext->IsoOnPlane(true) ;
98 /* create trihedron */
99 Handle(Geom_Axis2Placement) anAxis=new Geom_Axis2Placement(gp::XOY());
100 myTrihedron=new AIS_Trihedron(anAxis);
101 myTrihedron->SetInfiniteState( Standard_True );
103 Quantity_Color Col(193/255., 205/255., 193/255., Quantity_TOC_RGB);
104 myTrihedron->SetColor( Col );
105 myTrihedron->SetArrowColor( Col.Name() );
108 QString Size = QAD_CONFIG->getSetting("Viewer:TrihedronSize");
109 if (!Size. isEmpty() ) dim = Size.toFloat(); //get size from preferences
111 myTrihedron->SetSize(dim);
113 myAISContext->Display(myTrihedron);
114 myAISContext->Deactivate(myTrihedron);
116 /* create selector */
117 myAISSelector = new OCCViewer_AISSelector ( myAISContext );
118 QAD_ASSERT ( connect (myAISSelector, SIGNAL(selSelectionDone(bool)),
119 this, SLOT(onSelectionDone(bool))) );
120 QAD_ASSERT ( connect (myAISSelector, SIGNAL(selSelectionCancel(bool)),
121 this, SLOT(onSelectionCancel(bool))) );
122 myEnableSelection = true;
125 QAD_ASSERT ( connect(myViewFrame,
126 SIGNAL(vfKeyPress(QKeyEvent*)),
127 this, SLOT(onKeyPress(QKeyEvent*))) );
129 /* mouse events of the view */
130 QAD_ASSERT ( QObject::connect(myViewFrame,
131 SIGNAL(vfMousePress(QMouseEvent*)),
132 this, SLOT(onMousePress(QMouseEvent*))) );
133 QAD_ASSERT ( QObject::connect(myViewFrame,
134 SIGNAL(vfMouseRelease(QMouseEvent*)),
135 this, SLOT(onMouseRelease (QMouseEvent*))) );
136 QAD_ASSERT ( QObject::connect(myViewFrame,
137 SIGNAL(vfMouseMove(QMouseEvent*)),
138 this, SLOT(onMouseMove (QMouseEvent*))) );
139 QAD_ASSERT ( QObject::connect(myViewFrame,
140 SIGNAL(vfMouseDoubleClick(QMouseEvent*)),
141 this, SLOT(onMouseDoubleClick (QMouseEvent*))) );
143 /* transformation events */
144 QAD_ASSERT ( QObject::connect(myViewFrame,
145 SIGNAL(vfTransformationStarted(OCCViewer_ViewPort::OperationType)),
146 this, SLOT(onTransformationStarted (OCCViewer_ViewPort::OperationType))) );
147 QAD_ASSERT ( QObject::connect(myViewFrame,
148 SIGNAL(vfTransformationFinished(OCCViewer_ViewPort::OperationType)),
149 this, SLOT(onTransformationFinished (OCCViewer_ViewPort::OperationType))) );
151 /* set popup manager for the viewport */
152 myViewFrame->getViewPort()->setPopupServer ( this );
160 OCCViewer_Viewer3d::~OCCViewer_Viewer3d()
162 delete myAISSelector;
167 Handle(AIS_Trihedron) OCCViewer_Viewer3d::getTrihedron() const
172 void OCCViewer_Viewer3d::setTrihedronSize(float size)
174 myTrihedron->SetSize(size);
175 myAISContext->UpdateCurrentViewer();
178 bool OCCViewer_Viewer3d::isTrihedronDisplayed()
181 return myAISContext->IsDisplayed(myTrihedron);
184 void OCCViewer_Viewer3d::rename( const Handle(SALOME_InteractiveObject)& IObject, QString newName )
186 AIS_ListOfInteractive List;
187 myAISContext->DisplayedObjects(List);
189 AIS_ListIteratorOfListOfInteractive ite(List);
191 if (ite.Value()->IsKind(STANDARD_TYPE(SALOME_AISShape))) {
192 Handle(SALOME_AISShape) aSh =
193 Handle(SALOME_AISShape)::DownCast(ite.Value());
195 if ( aSh->hasIO() ) {
196 Handle(SALOME_InteractiveObject) IO = aSh->getIO();
197 if ( IO->isSame( IObject ) ) {
198 aSh->setName( strdup(newName.latin1()) );
202 } else if (ite.Value()->IsKind(STANDARD_TYPE(SALOME_AISObject))) {
203 Handle(SALOME_AISObject) aSh =
204 Handle(SALOME_AISObject)::DownCast(ite.Value());
206 // Add code here, if someone create a MODULE_AISObject.
212 void OCCViewer_Viewer3d::SetColor(const Handle(SALOME_InteractiveObject)& IObject,
215 AIS_ListOfInteractive List;
216 myAISContext->DisplayedObjects(List);
218 AIS_ListIteratorOfListOfInteractive ite(List);
220 if (ite.Value()->IsKind(STANDARD_TYPE(SALOME_AISShape))) {
221 Handle(SALOME_AISShape) aSh =
222 Handle(SALOME_AISShape)::DownCast(ite.Value());
224 if ( aSh->hasIO() ) {
225 Handle(SALOME_InteractiveObject) IO = aSh->getIO();
226 if ( IO->isSame( IObject ) ) {
227 Quantity_Color CSFColor = Quantity_Color ( thecolor.red()/255., thecolor.green()/255., thecolor.blue()/255., Quantity_TOC_RGB );
228 aSh->SetColor ( CSFColor );
229 // aSh->SetShadingColor ( CSFColor );
233 } else if (ite.Value()->IsKind(STANDARD_TYPE(SALOME_AISObject))) {
234 Handle(SALOME_AISObject) aSh =
235 Handle(SALOME_AISObject)::DownCast(ite.Value());
237 // Add code here, if someone create a MODULE_AISObject.
241 myV3dViewer->Update();
244 void OCCViewer_Viewer3d::SwitchRepresentation(const Handle(SALOME_InteractiveObject)& IObject,
247 AIS_ListOfInteractive List;
248 myAISContext->DisplayedObjects(List);
250 AIS_ListIteratorOfListOfInteractive ite(List);
252 if (ite.Value()->IsKind(STANDARD_TYPE(SALOME_AISShape))) {
253 Handle(SALOME_AISShape) aSh =
254 Handle(SALOME_AISShape)::DownCast(ite.Value());
256 if ( aSh->hasIO() ) {
257 Handle(SALOME_InteractiveObject) IO = aSh->getIO();
258 if ( IO->isSame( IObject ) ) {
259 myAISContext->SetDisplayMode(aSh,Standard_Integer(mode),true);
262 } else if (ite.Value()->IsKind(STANDARD_TYPE(SALOME_AISObject))) {
263 Handle(SALOME_AISObject) aSh =
264 Handle(SALOME_AISObject)::DownCast(ite.Value());
266 // Add code here, if someone create a MODULE_AISObject.
270 myV3dViewer->Update();
273 void OCCViewer_Viewer3d::SetTransparency(const Handle(SALOME_InteractiveObject)& IObject,
276 AIS_ListOfInteractive List;
277 myAISContext->DisplayedObjects(List);
279 AIS_ListIteratorOfListOfInteractive ite(List);
281 if (ite.Value()->IsKind(STANDARD_TYPE(SALOME_AISShape))) {
282 Handle(SALOME_AISShape) aSh =
283 Handle(SALOME_AISShape)::DownCast(ite.Value());
285 if ( aSh->hasIO() ) {
286 Handle(SALOME_InteractiveObject) IO = aSh->getIO();
287 if ( IO->isSame( IObject ) ) {
288 myAISContext->SetTransparency( aSh, transp, false );
289 myAISContext->Redisplay( aSh, Standard_False, Standard_True );
292 } else if (ite.Value()->IsKind(STANDARD_TYPE(SALOME_AISObject))) {
293 Handle(SALOME_AISObject) aSh =
294 Handle(SALOME_AISObject)::DownCast(ite.Value());
296 // Add code here, if someone create a MODULE_AISObject.
300 myV3dViewer->Update();
304 Highlights 'obj' in viewer, returns 'true' when selected successfully
306 bool OCCViewer_Viewer3d::highlight( const Handle(SALOME_InteractiveObject)& IObject, bool highlight, bool update )
308 AIS_ListOfInteractive List;
309 myAISContext->DisplayedObjects(List);
311 AIS_ListIteratorOfListOfInteractive ite(List);
313 if (ite.Value()->IsKind(STANDARD_TYPE(SALOME_AISShape))) {
314 Handle(SALOME_AISShape) aSh =
315 Handle(SALOME_AISShape)::DownCast(ite.Value());
317 if ( aSh->hasIO() ) {
318 Handle(SALOME_InteractiveObject) IO = aSh->getIO();
319 if ( IO->isSame( IObject ) ) {
321 if ( !myAISContext->IsSelected(aSh) )
322 myAISContext->AddOrRemoveCurrentObject(aSh, false);
324 if ( myAISContext->IsSelected(aSh) )
325 myAISContext->AddOrRemoveCurrentObject(aSh, false);
330 } else if (ite.Value()->IsKind(STANDARD_TYPE(SALOME_AISObject))) {
331 Handle(SALOME_AISObject) aSh =
332 Handle(SALOME_AISObject)::DownCast(ite.Value());
334 // Add code here, if someone create a MODULE_AISObject.
339 myV3dViewer->Update();
344 Unhighlight all selected objects
346 bool OCCViewer_Viewer3d::unHighlightAll()
348 myAISContext->ClearCurrents();
353 Returns true if the IObject has a Graphical Object in this viewer. Returns FALSE otherwise.
355 bool OCCViewer_Viewer3d::isInViewer( const Handle(SALOME_InteractiveObject)& IObject, bool onlyInViewer)
357 AIS_ListOfInteractive List;
358 myAISContext->DisplayedObjects(List);
360 if ( onlyInViewer ) {
361 AIS_ListOfInteractive List1;
362 myAISContext->ObjectsInCollector(List1);
366 AIS_ListIteratorOfListOfInteractive ite(List);
368 if (ite.Value()->IsKind(STANDARD_TYPE(SALOME_AISShape))) {
369 Handle(SALOME_AISShape) aSh =
370 Handle(SALOME_AISShape)::DownCast(ite.Value());
372 if ( aSh->hasIO() ) {
373 Handle(SALOME_InteractiveObject) IO = aSh->getIO();
374 if ( IObject->isSame( IO ) ) {
378 } else if (ite.Value()->IsKind(STANDARD_TYPE(SALOME_AISObject))) {
379 Handle(SALOME_AISObject) aSh =
380 Handle(SALOME_AISObject)::DownCast(ite.Value());
382 // Add code here, if someone create a MODULE_AISObject.
389 bool OCCViewer_Viewer3d::isVisible( const Handle(SALOME_InteractiveObject)& IObject )
391 AIS_ListOfInteractive List;
392 myAISContext->DisplayedObjects(List);
394 AIS_ListIteratorOfListOfInteractive ite(List);
396 if (ite.Value()->IsKind(STANDARD_TYPE(SALOME_AISShape))) {
397 Handle(SALOME_AISShape) aSh =
398 Handle(SALOME_AISShape)::DownCast(ite.Value());
400 if ( aSh->hasIO() ) {
401 Handle(SALOME_InteractiveObject) IO = aSh->getIO();
402 if ( IObject->isSame( IO ) ) {
403 return myAISContext->IsDisplayed(aSh);
406 } else if (ite.Value()->IsKind(STANDARD_TYPE(SALOME_AISObject))) {
407 Handle(SALOME_AISObject) aSh =
408 Handle(SALOME_AISObject)::DownCast(ite.Value());
410 // Add code here, if someone create a MODULE_AISObject.
418 Returns the interactive context
420 Handle (AIS_InteractiveContext) OCCViewer_Viewer3d::getAISContext() const
425 OCCViewer_AISSelector* OCCViewer_Viewer3d::getAISSelector() const
427 return myAISSelector;
431 Returns 'true' if selection is enabled in this viewer,
434 bool OCCViewer_Viewer3d::enabledSelection() const
436 return myEnableSelection;
440 Enables/disables selection in the viewer
442 void OCCViewer_Viewer3d::enableSelection( bool enable )
444 myEnableSelection = enable;
445 myAISSelector->enableSelection( enable );
447 /* send notification */
448 emit vw3dSelectionEnabled( enable );
452 Enables/disables ordinary and multiple selection
453 ( by 'Shift' key or with a rectangle ) in this viewer.
455 void OCCViewer_Viewer3d::enableMultipleSelection( bool enable )
457 /* Enable/disable rectangle skectching which
458 is used for multiple selection */
459 myAISSelector->enableMultipleSelection( enable );
461 myViewFrame->getViewPort()->enableDrawMode( enable );
463 /* Enable non-multiple selection as well */
464 if ( !myEnableSelection && enable )
465 enableSelection( enable );
471 void OCCViewer_Viewer3d::onKeyPress( QKeyEvent* pe )
473 if (!QAD_Application::getDesktop()->getActiveComponent().isEmpty()) {
474 QAD_Application::getDesktop()->onKeyPress( pe );
481 void OCCViewer_Viewer3d::onMousePress( QMouseEvent* pe )
483 if ( pe->button() == Qt::LeftButton ) {
484 if ( !QAD_Application::getDesktop()->onMousePress( pe ) ) {
486 QAD_ASSERT_DEBUG_ONLY ( myAISSelector );
487 if ( pe->state() & Qt::ShiftButton )
488 myAISSelector->shiftSelect(); /* append selection */
490 myAISSelector->select(); /* new selection */
498 void OCCViewer_Viewer3d::onMouseMove( QMouseEvent* pe )
500 /* activate hilighting only if no MB pressed */
501 if ( pe->state() == Qt::NoButton )
503 QAD_Application::getDesktop()->onMouseMove( pe );
505 OCCViewer_ViewPort* vp = myViewFrame->getViewPort();
506 myAISSelector->moveTo ( pe->x(), pe->y(), ((OCCViewer_ViewPort3d*)vp)->getView() );
513 void OCCViewer_Viewer3d::onMouseRelease( QMouseEvent* pe )
515 /* Selection with a rectangle ( multiple ) */
516 OCCViewer_ViewPort* vp = myViewFrame->getViewPort();
517 QAD_ASSERT_DEBUG_ONLY ( vp );
518 QRect selRect = vp->getSelectionRect ();
519 if ( selRect.isValid() ) {
520 QAD_ASSERT_DEBUG_ONLY ( myAISSelector );
521 QAD_ASSERT_DEBUG_ONLY ( vp->inherits("OCCViewer_ViewPort3d") );
522 if ( pe->state() & Qt::ShiftButton )
523 myAISSelector->shiftSelect ( selRect.left(), selRect.top(),
524 selRect.right(), selRect.bottom(),
525 ((OCCViewer_ViewPort3d*)vp)->getView() );
527 myAISSelector->select ( selRect.left(), selRect.top(),
528 selRect.right(), selRect.bottom(),
529 ((OCCViewer_ViewPort3d*)vp)->getView() );
536 void OCCViewer_Viewer3d::onMouseDoubleClick( QMouseEvent* pe )
541 Called when a transformation in viewport is started
543 void OCCViewer_Viewer3d::onTransformationStarted( OCCViewer_ViewPort::OperationType type )
545 QAD_ASSERT_DEBUG_ONLY ( myAISSelector );
546 if ( myEnableSelection )
547 myAISSelector->enableSelection ( false ); // lock until the end of transform
549 if ( type == OCCViewer_ViewPort::PANGLOBAL ||
550 type == OCCViewer_ViewPort::WINDOWFIT )
552 /* Start watching 'global panning' and 'window fit'.
553 These operations require additional user's actions
554 in viewport and we have to reset the operations if
555 instead of these actions a user does something else.
557 qApp->installEventFilter( this );
562 Called when a transformation in viewport is finished
564 void OCCViewer_Viewer3d::onTransformationFinished( OCCViewer_ViewPort::OperationType type )
566 QAD_ASSERT_DEBUG_ONLY ( myAISSelector );
567 if ( myEnableSelection )
568 myAISSelector->enableSelection ( true ); // unlock
570 if ( type == OCCViewer_ViewPort::PANGLOBAL ||
571 type == OCCViewer_ViewPort::WINDOWFIT )
573 /* stop watching 'global panning' and 'window fit'*/
574 qApp->removeEventFilter( this );
579 Called when an object is selected
581 void OCCViewer_Viewer3d::onSelectionDone( bool bAdded )
583 emit vw3dSelectionDone( bAdded );
585 QAD_Study* myActiveStudy = QAD_Application::getDesktop()->getActiveStudy();
586 QAD_StudyFrame* myActiveSFrame = myActiveStudy->getActiveStudyFrame();
587 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
588 MESSAGE ( "OCCViewer_Viewer3d - NB SELECTED INTERACTIVE OBJECT : " << Sel->IObjectCount() )
590 QString ActiveComp = QAD_Application::getDesktop()->getActiveComponent();
592 if ( ActiveComp.isEmpty() ) {
597 SALOME_ListIO DeltaPos;
599 SALOME_ListIO DeltaNeg;
602 if ( !bAdded ) { /* select */
603 myAISContext->InitCurrent();
604 while (myAISContext->MoreCurrent()) {
605 if (myAISContext->Current()->IsKind(STANDARD_TYPE(SALOME_AISShape))) {
606 Handle(SALOME_AISShape) aSh =
607 Handle(SALOME_AISShape)::DownCast(myAISContext->Current());
609 if ( aSh->hasIO() ) {
610 Handle( SALOME_InteractiveObject) IO = aSh->getIO();
612 bool itemAllreadySelected = false;
613 int nbSel = Sel->IObjectCount();
615 DeltaPos.Append( IO );
617 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
618 for(;It.More();It.Next()) {
619 Handle( SALOME_InteractiveObject) IO1 = It.Value();
620 if ( IO->isSame( IO1 ) ) {
621 itemAllreadySelected = true;
625 if (!itemAllreadySelected)
626 DeltaPos.Append( IO );
629 } else if (myAISContext->Current()->IsKind(STANDARD_TYPE(SALOME_AISObject))) {
630 Handle(SALOME_AISObject) aSh =
631 Handle(SALOME_AISObject)::DownCast(myAISContext->Current());
633 // Add code here, if someone create a MODULE_AISObject.
635 myAISContext->NextCurrent();
638 if ( DeltaPos.Extent() > 0 )
639 Sel->ClearIObjects();
641 } else { /* shift select */
642 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
643 for(;It.More();It.Next()) {
644 Handle( SALOME_InteractiveObject) IO1 = It.Value();
646 bool itemAllreadySelected = false;
647 myAISContext->InitCurrent();
648 while (myAISContext->MoreCurrent()) {
649 if (myAISContext->Current()->IsKind(STANDARD_TYPE(SALOME_AISShape))) {
650 Handle(SALOME_AISShape) aSh =
651 Handle(SALOME_AISShape)::DownCast(myAISContext->Current());
652 if ( aSh->hasIO() ) {
653 Handle( SALOME_InteractiveObject) IO = aSh->getIO();
655 if ( IO->isSame( IO1 ) ) {
656 itemAllreadySelected = true;
660 } else if (myAISContext->Current()->IsKind(STANDARD_TYPE(SALOME_AISObject))) {
661 Handle(SALOME_AISObject) aSh =
662 Handle(SALOME_AISObject)::DownCast(myAISContext->Current());
664 // Add code here, if someone create a MODULE_AISObject.
666 myAISContext->NextCurrent();
669 if (!itemAllreadySelected)
670 DeltaNeg.Append( IO1 );
673 myAISContext->InitCurrent();
674 while (myAISContext->MoreCurrent()) {
675 if (myAISContext->Current()->IsKind(STANDARD_TYPE(SALOME_AISShape))) {
676 Handle(SALOME_AISShape) aSh =
677 Handle(SALOME_AISShape)::DownCast(myAISContext->Current());
678 if ( aSh->hasIO() ) {
679 Handle( SALOME_InteractiveObject) IO = aSh->getIO();
681 bool itemAllreadySelected = false;
682 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
683 for(;It.More();It.Next()) {
684 Handle( SALOME_InteractiveObject) IO1 = It.Value();
686 if ( IO->isSame( IO1 ) ) {
687 itemAllreadySelected = true;
692 if (!itemAllreadySelected )
693 DeltaPos.Append( IO );
695 } else if ( myAISContext->Current()->IsKind(STANDARD_TYPE(SALOME_AISObject))) {
696 Handle(SALOME_AISObject) aSh =
697 Handle(SALOME_AISObject)::DownCast(myAISContext->Current());
699 // Add code here, if someone create a MODULE_AISObject.
701 myAISContext->NextCurrent();
705 // MESSAGE ( "VIEWER onSelectionDone DeltaNeg.count() == " << DeltaNeg.count() )
706 SALOME_ListIteratorOfListIO ItNeg( DeltaNeg );
707 for(;ItNeg.More();ItNeg.Next()) {
708 Sel->RemoveIObject( ItNeg.Value(), false );
711 // MESSAGE ( "VIEWER onSelectionDone DeltaPos.count() == " << DeltaPos.Extent() )
712 SALOME_ListIteratorOfListIO ItPos( DeltaPos );
713 for(;ItPos.More();ItPos.Next()) {
714 Sel->AddIObject( ItPos.Value(), false );
716 myV3dViewer->Update();
720 Called when an object is unselected
722 void OCCViewer_Viewer3d::onSelectionCancel( bool bAdded )
724 emit vw3dSelectionCancel();
726 QAD_Study* myActiveStudy = QAD_Application::getDesktop()->getActiveStudy();
727 QAD_StudyFrame* myActiveSFrame = myActiveStudy->getActiveStudyFrame();
728 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
730 // MESSAGE ( "OCCViewer_Viewer3d - NB SELECTED INTERACTIVE OBJECT : " << Sel->IObjectCount() )
732 SALOME_ListIO DeltaPos;
734 SALOME_ListIO DeltaNeg;
736 if (!bAdded) { /* select */
737 Sel->ClearIObjects();
738 } else { /* shiftselect */
739 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
740 for(;It.More();It.Next()) {
741 Handle( SALOME_InteractiveObject) IO1 = It.Value();
743 bool itemAllreadySelected = false;
744 myAISContext->InitCurrent();
745 while (myAISContext->MoreCurrent()) {
746 if (myAISContext->Current()->IsKind(STANDARD_TYPE(SALOME_AISShape))) {
747 Handle(SALOME_AISShape) aSh =
748 Handle(SALOME_AISShape)::DownCast(myAISContext->Current());
749 if ( aSh->hasIO() ) {
750 Handle( SALOME_InteractiveObject) IO = aSh->getIO();
751 if ( IO->isSame(IO1) ) {
752 itemAllreadySelected = true;
756 } else if (myAISContext->Current()->IsKind(STANDARD_TYPE(SALOME_AISObject))) {
757 Handle(SALOME_AISObject) aSh =
758 Handle(SALOME_AISObject)::DownCast(myAISContext->Current());
760 // Add code here, if someone create a MODULE_AISObject.
762 myAISContext->NextCurrent();
766 if (!itemAllreadySelected)
767 DeltaNeg.Append( IO1 );
771 // MESSAGE ( "VIEWER onSelectionCancel DeltaNeg.count() == " << DeltaNeg.Extent() )
772 SALOME_ListIteratorOfListIO ItNeg( DeltaNeg );
773 for(;ItNeg.More();ItNeg.Next()) {
774 Sel->RemoveIObject( ItNeg.Value(), false);
776 myV3dViewer->Update();
780 Installed while 'fit area' and 'global panning'
781 operations are active
783 bool OCCViewer_Viewer3d::eventFilter( QObject * po, QEvent * pe)
785 if ( ( pe->type() == QEvent::MouseButtonPress &&
786 po != myViewFrame->getViewPort() ) ||
787 pe->type() == QEvent::KeyPress ) {
788 /* user press any key or a MB outside the viewport */
789 myViewFrame->getViewPort()->resetState();
791 return QObject::eventFilter( po, pe );
795 Creates CasCade viewer 3D
797 void OCCViewer_Viewer3d::createViewer3d()
799 myV3dViewer = OCCViewer_VService::Viewer ( "", (short*) "Viewer3d", "", 1000.,
800 V3d_XposYnegZpos, true, true);
803 myV3dCollector = OCCViewer_VService::Viewer ( "", (short*) "Collector3d", "", 1000.,
804 V3d_XposYnegZpos, true, true);
805 myV3dCollector->Init();
809 Returns CasCade viewer 3D
811 Handle(V3d_Viewer) OCCViewer_Viewer3d::getViewer3d() const
817 Sets a new cursor on all its studyframes
819 void OCCViewer_Viewer3d::setCursor( const QCursor& cursor)
825 Returns the current cursor
827 inline const QCursor& OCCViewer_Viewer3d::cursor() const
833 Sets default background color on all its studyframes
835 void OCCViewer_Viewer3d::setBackgroundColor( const QColor& aColor )
837 myBackColor = aColor;
841 Returns the current background
843 inline const QColor& OCCViewer_Viewer3d::backgroundColor() const
849 Sets a new icon to all its studyframes
851 void OCCViewer_Viewer3d::setIcon( const QPixmap& icon )
859 inline const QPixmap& OCCViewer_Viewer3d::icon() const
867 void OCCViewer_Viewer3d::onCreatePopup()