1 // GEOM GEOMGUI : GUI for Geometry component
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 : GEOM_Displayer.cxx
25 // Author : Vadim SANDLER
29 #include <SOCC_ViewModel.h>
31 #include "GEOM_Displayer.h"
32 #include "GEOMImpl_Types.hxx"
34 #include "GEOM_TypeFilter.h"
35 #include "GEOM_EdgeFilter.h"
36 #include "GEOM_FaceFilter.h"
37 #include "GEOM_PreviewFilter.h"
38 #include "GEOM_LogicalFilter.h"
39 #include "GEOM_OCCFilter.h"
41 #include "GEOM_AssemblyBuilder.h"
42 #include "GEOM_Actor.h"
43 #include "GEOM_AISTrihedron.hxx"
44 #include "GEOM_VTKTrihedron.hxx"
46 #include <SUIT_Desktop.h>
47 #include <SUIT_ViewWindow.h>
48 #include <SUIT_Session.h>
49 #include <SUIT_Tools.h>
50 #include <SUIT_ViewManager.h>
52 #include <SalomeApp_Study.h>
53 #include <SalomeApp_Application.h>
54 #include <SalomeApp_SelectionMgr.h>
55 #include <SalomeApp_TypeFilter.h>
56 #include <SalomeApp_Tools.h>
58 #include <SALOME_ListIteratorOfListIO.hxx>
59 #include <SALOMEDSClient.hxx>
60 #include <SALOMEDS_SObject.hxx>
61 #include <SALOMEDSClient_SObject.hxx>
66 #include <SVTK_ViewModel.h>
68 #include <TColStd_MapOfInteger.hxx>
69 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
71 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
73 #include <GeometryGUI.h>
74 #include <GEOM_AISShape.hxx>
75 #include <AIS_ListIteratorOfListOfInteractive.hxx>
76 #include <AIS_Drawer.hxx>
77 #include <Prs3d_PointAspect.hxx>
78 #include <Graphic3d_AspectMarker3d.hxx>
79 #include <Geom_Plane.hxx>
80 #include <TopoDS_Face.hxx>
81 #include <BRep_Tool.hxx>
83 #include <Geom_Axis2Placement.hxx>
84 #include <StdSelect_TypeOfEdge.hxx>
85 #include <StdSelect_TypeOfFace.hxx>
86 #include <vtkActorCollection.h>
92 //================================================================
93 // Function : getActiveStudy
94 // Purpose : Get active study, returns 0 if no open study frame
95 //================================================================
96 static inline SalomeApp_Study* getActiveStudy()
98 SUIT_Session* session = SUIT_Session::session();
99 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
101 return ( SalomeApp_Study* )app->activeStudy();
105 //================================================================
106 // Function : getTopAbsMode
107 // Purpose : Get TopAbs_ShapeEnum value corresponding to the
108 // one from GEOMImpl_Types.h
109 //================================================================
110 static inline int getTopAbsMode( const int implType )
114 case GEOM_COMPOUND : return TopAbs_COMPOUND;
115 case GEOM_SOLID : return TopAbs_SOLID;
116 case GEOM_SHELL : return TopAbs_SHELL;
117 case GEOM_FACE : return TopAbs_FACE;
118 case GEOM_WIRE : return TopAbs_WIRE;
119 case GEOM_EDGE : return TopAbs_EDGE;
120 case GEOM_POINT : return TopAbs_VERTEX;
125 //================================================================
126 // Function : getFilter
127 // Purpose : Get filter corresponding to the type of object
128 // from GEOMImpl_Types.h
129 //================================================================
130 SUIT_SelectionFilter* GEOM_Displayer::getFilter( const int theMode )
132 SUIT_SelectionFilter* aFilter;
134 int aTopAbsMode = getTopAbsMode( theMode );
135 if ( aTopAbsMode != -1 )
136 aFilter = new GEOM_TypeFilter( getStudy(), aTopAbsMode, true ); //@ aFilter = new GEOM_TypeFilter( ( TopAbs_ShapeEnum )aTopAbsMode );
140 case GEOM_LINE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Line ); break;
141 case GEOM_CIRCLE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Circle ); break;
143 case GEOM_PLANE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Plane ); break;
144 case GEOM_CYLINDER : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cylinder ); break;
145 case GEOM_SPHERE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Sphere ); break;
146 case GEOM_TORUS : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Torus ); break;
147 case GEOM_REVOLUTION: aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Revol ); break;
148 case GEOM_CONE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cone ); break;
150 case GEOM_PREVIEW : aFilter = new GEOM_PreviewFilter( getStudy() ); break;
152 case GEOM_ALLSHAPES : aFilter = new GEOM_SelectionFilter(getStudy(), true ); break;
153 case GEOM_ALLGEOM : aFilter = new SalomeApp_TypeFilter( getStudy(), "GEOM" ); break;
155 default : aFilter = new GEOM_TypeFilter( getStudy(), theMode ); break;
161 //================================================================
162 // Function : getEntry
164 //================================================================
165 static char* getEntry( GEOM::GEOM_Object_ptr object )
167 SUIT_Session* session = SUIT_Session::session();
168 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
171 string IOR = app->orb()->object_to_string( object );
174 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
175 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( IOR ) );
177 return (char*)(SO->GetID().c_str());
183 //================================================================
184 // Function : getName
186 //================================================================
187 static const char* getName( GEOM::GEOM_Object_ptr object )
189 SUIT_Session* session = SUIT_Session::session();
190 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
193 string IOR = app->orb()->object_to_string( object );
196 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
197 _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( IOR ) );
199 _PTR(GenericAttribute) anAttr;
201 if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
203 _PTR(AttributeName) aNameAttr( anAttr );
204 return aNameAttr->Value().c_str();
212 //=================================================================
214 * GEOM_Displayer::GEOM_Displayer
217 //=================================================================
218 GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* study )
223 SUIT_Session* session = SUIT_Session::session();
224 SUIT_ResourceMgr* resMgr = session->resourceMgr();
226 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
227 myShadingColor = SalomeApp_Tools::color( col );
230 // This color is used for shape displaying. If it is equal -1 then
231 // default color is used.
237 // This parameter is used for activisation/deactivisation of objects to be displayed
242 //=================================================================
244 * GEOM_Displayer::~GEOM_Displayer
247 //=================================================================
248 GEOM_Displayer::~GEOM_Displayer()
252 //=================================================================
255 * Get active study frame, returns 0 if no open study frame
257 //=================================================================
258 SALOME_View* GEOM_Displayer::GetActiveView()
260 SUIT_Session* session = SUIT_Session::session();
261 SUIT_Application* app = session->activeApplication();
264 SUIT_Desktop* desk = app->desktop();
267 SUIT_ViewWindow* win = desk->activeWindow();
270 SUIT_ViewManager* vman = win->getViewManager();
273 SUIT_ViewModel* vmodel = vman->getViewModel();
276 SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
286 //=================================================================
288 * GEOM_Displayer::Display
289 * Display interactive object in the current viewer
291 //=================================================================
292 void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO,
293 const bool updateViewer,
294 SALOME_View* theViewFrame )
296 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
299 SALOME_Prs* prs = buildPresentation( theIO, vf );
303 vf->BeforeDisplay( this );
305 vf->AfterDisplay( this );
310 delete prs; // delete presentation because displayer is its owner
315 //=================================================================
317 * GEOM_Displayer::Display
318 * This overloaded Display() method can be useful for operations
319 * not using dialog boxes.
321 //=================================================================
322 void GEOM_Displayer::Display( GEOM::GEOM_Object_ptr theObj, const bool updateViewer )
324 if ( theObj->_is_nil() )
327 string entry = getEntry( theObj );
329 Display( new SALOME_InteractiveObject(
330 entry.c_str(), "GEOM", strdup( getName( theObj ) ) ), updateViewer );
334 //=================================================================
336 * GEOM_Displayer::Erase
337 * Erase interactive object in the current viewer
339 //=================================================================
340 void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO,
342 const bool updateViewer,
343 SALOME_View* theViewFrame )
345 if ( theIO.IsNull() )
348 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
351 SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() );
353 vf->Erase( prs, forced );
356 delete prs; // delete presentation because displayer is its owner
361 //=================================================================
363 * GEOM_Displayer::Erase
364 * Erase geometry object in the current viewer
366 //=================================================================
367 void GEOM_Displayer::Erase( GEOM::GEOM_Object_ptr theObj,
369 const bool updateViewer )
371 string entry = getEntry( theObj );
374 Erase( new SALOME_InteractiveObject(
375 entry.c_str(), "GEOM", strdup( getName( theObj ) ) ), forced, updateViewer );
379 //=================================================================
381 * GEOM_Displayer::EraseAll
382 * Erase all objects in the current viewer
384 //=================================================================
385 void GEOM_Displayer::EraseAll ( const bool forced,
386 const bool updateViewer,
387 SALOME_View* theViewFrame )
389 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
392 vf->EraseAll( forced );
398 //=================================================================
400 * GEOM_Displayer::Redisplay
401 * Redisplay (erase and then display again) interactive object
402 * in the current viewer
404 //=================================================================
405 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
406 const bool updateViewer )
408 // Remove the object permanently (<forced> == true)
409 SUIT_Session* ses = SUIT_Session::session();
410 SUIT_Application* app = ses->activeApplication();
413 SUIT_Desktop* desk = app->desktop();
414 QPtrList<SUIT_ViewWindow> wnds = desk->windows();
415 SUIT_ViewWindow* wnd;
416 for ( wnd = wnds.first(); wnd; wnd = wnds.next() )
418 SUIT_ViewManager* vman = wnd->getViewManager();
421 SUIT_ViewModel* vmodel = vman->getViewModel();
424 SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
427 if ( view->isVisible( theIO ) || view == GetActiveView() )
429 Erase( theIO, true, false, view );
430 Display( theIO, updateViewer, view );
439 //=================================================================
441 * GEOM_Displayer::Display
442 * Calls Display() method for each object in the given list
444 //=================================================================
445 void GEOM_Displayer::Display( const SALOME_ListIO& theIOList, const bool updateViewer )
447 SALOME_ListIteratorOfListIO Iter( theIOList );
448 for ( ; Iter.More(); Iter.Next() ) {
449 Display( Iter.Value(), false );
455 //=================================================================
457 * GEOM_Displayer::Erase
458 * Calls Erase() method for each object in the given list
460 //=================================================================
461 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
463 const bool updateViewer )
465 SALOME_ListIteratorOfListIO Iter( theIOList );
466 for ( ; Iter.More(); Iter.Next() )
467 Erase( Iter.Value(), forced, false );
473 //=================================================================
475 * GEOM_Displayer::Redisplay
476 * Calls Redisplay() method for each object in the given list
478 //=================================================================
479 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList, const bool updateViewer )
481 SALOME_ListIteratorOfListIO Iter( theIOList );
482 for ( ; Iter.More(); Iter.Next() )
483 Redisplay( Iter.Value(), false );
489 //=================================================================
491 * GEOM_Displayer::UpdateViewer
492 * Update current viewer
494 //=================================================================
495 void GEOM_Displayer::UpdateViewer()
497 SALOME_View* vf = GetActiveView();
502 //=================================================================
504 * GEOM_Displayer::Update
505 * Update OCC presentaion
506 * [ Reimplemented from SALOME_Displayer ]
508 //=================================================================
509 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
511 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
515 if ( myType == GEOM_MARKER && !myShape.IsNull() && myShape.ShapeType() == TopAbs_FACE )
517 TopoDS_Face aFace = TopoDS::Face( myShape );
518 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
519 if ( !aPlane.IsNull() )
521 gp_Ax3 aPos = aPlane->Pln().Position();
522 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
524 Handle(GEOM_AISTrihedron) aTrh;
526 if ( occPrs->IsNull() )
528 aTrh = new GEOM_AISTrihedron( aPlc );
531 aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
534 aTrh->SetWidth( GetWidth() );
536 if ( !myIO.IsNull() )
539 aTrh->SetOwner( myIO );
542 occPrs->AddObject( aTrh );
546 AIS_ListOfInteractive aList;
547 occPrs->GetObjects( aList );
548 AIS_ListIteratorOfListOfInteractive anIter( aList );
549 for ( ; anIter.More(); anIter.Next() )
551 aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
552 if ( !aTrh.IsNull() )
554 aTrh->SetComponent( aPlc );
560 occPrs->SetToActivate( ToActivate() );
565 // if presentation is empty we try to create new one
566 if ( occPrs->IsNull() )
568 if ( !myShape.IsNull() )
570 Handle(GEOM_AISShape) AISShape = new GEOM_AISShape( myShape, "" );
571 // Temporary staff: vertex must be infinite for correct visualization
572 AISShape->SetInfiniteState( myShape.Infinite() || myShape.ShapeType() == TopAbs_VERTEX );
574 // Setup shape properties here ..., e.g. display mode, color, transparency, etc
575 AISShape->SetShadingColor( myShadingColor );
578 AISShape->SetColor( (Quantity_NameOfColor)GetColor() );
579 if ( myShape.ShapeType() == TopAbs_VERTEX )
581 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
582 anAspect->SetColor( (Quantity_NameOfColor)GetColor() );
583 AISShape->Attributes()->SetPointAspect( anAspect );
588 AISShape->SetWidth( GetWidth() );
590 if ( !myIO.IsNull() )
592 AISShape->setIO( myIO );
593 AISShape->SetOwner( myIO );
595 else if ( !myName.empty() )
597 // Workaround to allow selection of temporary objects
598 static int tempId = 0;
600 sprintf( buf, "TEMP_%d", tempId++ );
601 Handle( SALOME_InteractiveObject ) anObj =
602 new SALOME_InteractiveObject( buf, "GEOM", myName.c_str() );
603 AISShape->setIO( anObj );
604 AISShape->SetOwner( anObj );
606 // AISShape->SetName(???); ??? necessary to set name ???
607 occPrs->AddObject( AISShape );
609 // In accordance with ToActivate() value object will be activated/deactivated
610 // when it will be displayed
611 occPrs->SetToActivate( ToActivate() );
614 // if presentation is found -> set again shape for it
617 if ( !myShape.IsNull() )
619 AIS_ListOfInteractive IOList;
620 occPrs->GetObjects( IOList );
621 AIS_ListIteratorOfListOfInteractive Iter( IOList );
622 for ( ; Iter.More(); Iter.Next() )
624 Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
625 if ( AISShape.IsNull() )
627 if ( AISShape->Shape() != myShape )
629 AISShape->Set( myShape );
630 AISShape->UpdateSelection();
631 AISShape->SetToUpdate();
633 if ( !myIO.IsNull() )
635 AISShape->setIO( myIO );
636 AISShape->SetOwner( myIO );
644 //=================================================================
646 * GEOM_Displayer::Update
647 * Update VTK presentaion
648 * [ Reimplemented from SALOME_Displayer ]
650 //=================================================================
651 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
653 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
654 if ( !vtkPrs || myShape.IsNull() )
657 vtkActorCollection* theActors = 0;
659 if ( myType == GEOM_MARKER && !myShape.IsNull() && myShape.ShapeType() == TopAbs_FACE )
661 myToActivate = false;
662 GEOM_VTKTrihedron* aTrh = GEOM_VTKTrihedron::New();
666 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
667 aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
670 Handle(Geom_Plane) aPlane =
671 Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( TopoDS::Face( myShape ) ) );
672 if ( aPlane.IsNull() )
675 gp_Ax2 anAx2 = aPlane->Pln().Position().Ax2();
676 aTrh->SetPlacement( new Geom_Axis2Placement( anAx2 ) );
678 // if ( SVTK_Viewer* vf = dynamic_cast<SVTK_Viewer*>( GetActiveView() ) )
679 // aTrh->SetSize( 0.5 * vf->GetTrihedronSize() );
681 vtkPrs->AddObject( aTrh );
683 theActors = vtkActorCollection::New();
684 theActors->AddItem( aTrh );
687 theActors = GEOM_AssemblyBuilder::BuildActors( myShape, 0, 0, Standard_True );
689 theActors->InitTraversal();
691 vtkActor* anActor = (vtkActor*)theActors->GetNextActor();
693 vtkProperty* aProp = 0;
695 if ( HasColor() || HasWidth() )
697 aProp = vtkProperty::New();
698 aProp->SetRepresentationToWireframe();
703 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
704 aProp->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
709 aProp->SetLineWidth( GetWidth() );
712 while ( anActor != NULL )
714 SALOME_Actor* GActor = SALOME_Actor::SafeDownCast( anActor );
716 GActor->setIO( myIO );
720 GActor->SetProperty( aProp );
721 GActor->SetPreviewProperty( aProp );
723 GEOM_Actor* aGeomGActor = GEOM_Actor::SafeDownCast( anActor );
724 if ( aGeomGActor != 0 )
726 aGeomGActor->SetShadingProperty( aProp );
727 aGeomGActor->SetWireframeProperty( aProp );
732 GActor->PickableOn();
734 GActor->PickableOff();
736 vtkPrs->AddObject( GActor );
738 anActor = (vtkActor*)theActors->GetNextActor();
747 //=================================================================
749 * GEOM_Displayer::BuildPrs
750 * Build presentation accordint to the current viewer type
752 //=================================================================
753 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
755 if ( theObj->_is_nil() )
758 myViewFrame = GetActiveView();
759 if ( myViewFrame == 0 )
762 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
767 setShape( GEOM_Client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
768 myType = theObj->GetType();
770 // Update presentation
776 //=================================================================
778 * GEOM_Displayer::BuildPrs
779 * Build presentation accordint to the current viewer type
781 //=================================================================
782 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
784 myViewFrame = GetActiveView();
785 if ( theShape.IsNull() || myViewFrame == 0 )
788 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
793 setShape( theShape );
801 //=================================================================
803 * GEOM_Displayer::buildPresentation
804 * Builds/finds object's presentation for the current viewer
805 * Calls corresponding Update() method by means of double dispatch
808 //=================================================================
809 SALOME_Prs* GEOM_Displayer::buildPresentation( const Handle(SALOME_InteractiveObject)& theIO,
810 SALOME_View* theViewFrame )
815 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
819 prs = myViewFrame->CreatePrs( !theIO.IsNull() ? theIO->getEntry() : 0 );
822 if ( !theIO.IsNull() )
824 // set interactive object
826 // Find SOBject (because shape should be published previously)
827 SUIT_Session* session = SUIT_Session::session();
828 SUIT_Application* app = session->activeApplication();
831 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
834 _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
837 // get CORBA reference to data object
838 CORBA::Object_var object = dynamic_cast<SALOMEDS_SObject*>(SO.get())->GetObject();
839 if ( !CORBA::is_nil( object ) )
841 // downcast to GEOM object
842 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( object );
843 if ( !GeomObject->_is_nil() )
846 setShape( GEOM_Client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
847 myType = GeomObject->GetType();
854 UpdatePrs( prs ); // Update presentation by using of the double dispatch
860 //=================================================================
862 * GEOM_Displayer::internalReset
863 * Resets internal data
866 //=================================================================
867 void GEOM_Displayer::internalReset()
873 //=================================================================
875 * GEOM_Displayer::LocalSelection
876 * Activate selection of CAD shapes with activisation of selection
877 * of their sub-shapes (with opened local context for OCC viewer)
879 //=================================================================
880 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
882 SUIT_Session* session = SUIT_Session::session();
883 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
887 SalomeApp_SelectionMgr* sm = app->selectionMgr();
889 // remove all filters from selection
892 SALOME_View* vf = GetActiveView();
895 SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
896 vf->LocalSelection( prs, theMode );
897 delete prs; // delete presentation because displayer is its owner
901 //=================================================================
903 * GEOM_Displayer::globalSelection
904 * Activate selection of CAD shapes without activisation of selection
905 * of their sub-shapes (without opened local context for OCC viewer)
907 //=================================================================
908 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
910 TColStd_MapOfInteger aModes;
911 aModes.Add( theMode );
912 GlobalSelection( aModes, update );
915 //=================================================================
917 * GEOM_Displayer::globalSelection
918 * Activate selection of CAD shapes without activisation of selection
919 * of their sub-shapes (without opened local context for OCC viewer)
921 //=================================================================
922 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
925 SUIT_Session* session = SUIT_Session::session();
926 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
930 SALOME_View* vf = GetActiveView();
934 // Close local context
935 vf->GlobalSelection( update );
937 // Set selection filters in accordance with current mode
938 SalomeApp_SelectionMgr* sm = app->selectionMgr();
942 // Remove from selection temporary objects if necessary
943 if ( !theModes.Contains( GEOM_PREVIEW ) )
944 clearTemporary( sm );
946 //@ aSel->ClearIndex();
950 // Remove filters from AIS_InteractiveContext
951 Handle(AIS_InteractiveContext) ic;
952 SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
955 ic = viewer->getAISContext();
960 if ( theModes.Contains( GEOM_ALLOBJECTS ) )
963 SUIT_SelectionFilter* aFilter;
964 if ( theModes.Extent() == 1 )
966 int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
967 aFilter = getFilter( aMode );
969 else if ( theModes.Extent() > 1 )
971 TColStd_MapOfInteger aTopAbsModes;
972 TColStd_MapIteratorOfMapOfInteger anIter( theModes );
973 QPtrList<SUIT_SelectionFilter> aListOfFilters;
974 for ( ; anIter.More(); anIter.Next() )
976 SUIT_SelectionFilter* aFilter = getFilter( anIter.Key() );
978 aListOfFilters.append( aFilter );
981 aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
988 sm->installFilter( aFilter );
991 Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
992 ic->AddFilter( anOCCFilter );
997 //=================================================================
999 * GEOM_Displayer::LocalSelection
1000 * Activate selection of CAD shapes with activisation of selection
1001 * of their sub-shapes (with opened local context for OCC viewer)
1003 //=================================================================
1004 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
1006 SALOME_ListIteratorOfListIO Iter( theIOList );
1007 for ( ; Iter.More(); Iter.Next() )
1008 LocalSelection( Iter.Value(), theMode );
1011 //=================================================================
1013 * GEOM_Displayer::BeforeDisplay
1014 * Called before displaying of pars. Close local context
1015 * [ Reimplemented from SALOME_Displayer ]
1017 //=================================================================
1018 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCViewType& )
1020 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1023 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1026 if ( ic->HasOpenedContext() )
1027 ic->CloseAllContexts();
1032 void GEOM_Displayer::AfterDisplay( SALOME_View*, const SALOME_OCCViewType& )
1037 //=================================================================
1039 * GEOM_Displayer::SetColor
1040 * Set color for shape displaying. If it is equal -1 then default color is used.
1041 * Available values are from Quantity_NameOfColor enumeration
1043 //=================================================================
1044 void GEOM_Displayer::SetColor( const int color )
1049 int GEOM_Displayer::GetColor() const
1054 bool GEOM_Displayer::HasColor() const
1056 return myColor != -1;
1059 void GEOM_Displayer::UnsetColor()
1064 //=================================================================
1066 * GEOM_Displayer::SetWidth
1067 * Set width of shape displaying. If it is equal -1 then default width is used.
1069 //=================================================================
1070 void GEOM_Displayer::SetWidth( const double width )
1075 double GEOM_Displayer::GetWidth() const
1080 bool GEOM_Displayer::HasWidth() const
1082 return myWidth != -1;
1085 void GEOM_Displayer::UnsetWidth()
1090 //=================================================================
1092 * GEOM_Displayer::SetToActivate
1093 * This method is used for activisation/deactivisation of objects to be displayed
1095 //=================================================================
1096 void GEOM_Displayer::SetToActivate( const bool toActivate )
1098 myToActivate = toActivate;
1100 bool GEOM_Displayer::ToActivate() const
1102 return myToActivate;
1105 //=================================================================
1107 * GEOM_Displayer::clearTemporary
1108 * Removes from selection temporary objects
1110 //=================================================================
1111 void GEOM_Displayer::clearTemporary( SalomeApp_SelectionMgr* theSelMgr )
1113 SALOME_ListIO selected, toSelect;
1114 theSelMgr->selectedObjects( selected );
1116 for ( SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
1117 Handle(SALOME_InteractiveObject) io = it.Value();
1118 if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
1119 toSelect.Append( it.Value() );
1122 theSelMgr->setSelectedObjects( toSelect, true );